我有一个循环,每次迭代都会使margin-top减少182px.我想得到margin-top的值,所以我可以告诉它什么时候停止运行但是当我尝试在控制台中运行它时,它会返回"undefined"请告知如何更改它以获得真正的价值.
这是我正在使用的,我使用attr()因为它需要获得的值是内联样式:
$marginTop = $('.emp-wrap').attr("style");
Run Code Online (Sandbox Code Playgroud)
其余代码如下
// if statements to move carousel up
$carouselNum = $('.carousella').length;
$marginTop = $('.emp-wrap').attr("style");
if($carouselNum > 1){
// // function empMove, the '-=' allows the -margin-top to run every time. Without this it will set the margin-top to the same value every loop
function empMove() { $('.emp-wrap').css('margin-top', '-=182')};
setInterval(empMove, 20000);
}
else if($carousel < 1){
// do something
}
else{
// do something
}
Run Code Online (Sandbox Code Playgroud)