【问题标题】:Passing variable to .animate() function JQuery将变量传递给 .animate() 函数 JQuery
【发布时间】:2012-06-19 17:51:28
【问题描述】:

下面我有一个函数,它根据一个变量 (nextItem) 是否大于另一个 (currentItemRel) 来将 div (container) 向左或向右移动。

我遇到的问题是在.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 function variables if-statement jquery-animate


    【解决方案1】:

    jquery animate 函数的 += 和 -= 修饰符必须被解析为字符串。

    查看this fiddle

    【讨论】:

    • 我只是跳出框框思考并将其作为变量。谢谢,小提琴很棒!
    猜你喜欢
    • 1970-01-01
    • 2012-03-02
    • 2011-01-18
    • 2014-10-31
    • 1970-01-01
    • 1970-01-01
    • 2013-01-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多