下面我有一个函数,可以根据一个变量 (nextItem
) 是否大于另一个变量 (nextItem
) 向左或向右对 div(container
)进行动画处理( currentItemRel
)。
我遇到的问题是在 .animate()
函数中使用 distance
变量。
如何传递这个变量?目前我的 JavaScript 正在崩溃,因此我们将不胜感激。
谢谢
var distance = (nextItem - currentItemRel) * 1260;
if (nextItem > currentItemRel)
{
$('#container').animate({ left: -=distance }, 1200);
} else if (nextItem < currentItemRel)
{
$('#container').animate({ left: +=distance }, 1200);
};
最佳答案
jquery animate 函数的 += 和 -= 修饰符必须被解析为字符串。
关于jquery - 将变量传递给 .animate() 函数 JQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11071349/