在jQuery .animate中使用step选项时出错

时间:2015-11-02 10:04:34

标签: javascript jquery

我有以下代码:

$("#MainNavBar").animate({
        width: "48px"
    },
    1000,
    function () {
        console.log("complete!");
    }, {
        step: function (now, fx) {
            // var data = fx.elem.id + " " + fx.prop + ": " + now;
            // console.log(fx.prop);
            //  console.log(now);
        }
    });

在我添加步骤方法之前工作正常。

当我添加上述步骤方法时,我收到以下错误

  

TypeError:m.easing [this.easing]不是函数

现在我将jquery-ui包含在根布局文件中

<script src="~/Scripts/jquery-ui-1.10.3.min.js"></script>

任何人都可以指出我正确的方向和我出错的地方吗?

1 个答案:

答案 0 :(得分:2)

animate的参数顺序不正确。您正在使用的animate签名是

.animate( properties [, duration ] [, easing ] [, complete ] )

这里,它期望第三个参数作为缓动效果的名称(字符串)而不是函数。所以,错误

  

宽松不是一种功能

使用:

$("#MainNavBar").animate({
    width: "48px"
}, {
    duration: 1000,
    step: function () {
        // Code here
    }
},
function () {
    console.log("complete!");
});