.animate() 中的匿名回调函数不起作用

发布于 2024-09-28 23:39:23 字数 292 浏览 0 评论 0原文

我一生都无法弄清楚这段代码的问题是什么。动画本身运行良好:

if (!list.is(':animated')) {
    list.animate(
        {"top": "+="+item_size},
        {queue:false, duration:speed},
        function() {
            alert();
        }
    ); // end of animate function

} //end of if statement

I can't for the life of me figure out what the problem with this code is. The animation itself works fine:

if (!list.is(':animated')) {
    list.animate(
        {"top": "+="+item_size},
        {queue:false, duration:speed},
        function() {
            alert();
        }
    ); // end of animate function

} //end of if statement

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一抹微笑 2024-10-05 23:39:23

您混淆了 .animate() 的两个签名。您需要使回调成为 options 参数的一部分:

if(!list.is(':animated')){
    list.animate({
        top: "+="+item_size
    }, //end of properties argument
    {
        queue: false, 
        duration: speed,
        complete: function(){
            alert();
        } //end of callback
    }  // end of options argument
    ); // end of animate function
} //end of if statement

You're mixing up the two signatures of .animate(). You need to make the callback a part of the options argument:

if(!list.is(':animated')){
    list.animate({
        top: "+="+item_size
    }, //end of properties argument
    {
        queue: false, 
        duration: speed,
        complete: function(){
            alert();
        } //end of callback
    }  // end of options argument
    ); // end of animate function
} //end of if statement
魂牵梦绕锁你心扉 2024-10-05 23:39:23

检查 API,你似乎没有正确调用该函数:

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

猜猜你应该这样做调用它:

.animate( {"top": "+="+item_size}, speed, 'linear', function(){alert();});

将线性更改为您需要的任何缓动函数。

Check the API, you don't seem to be calling the function right:

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

Guess this is how you should call it:

.animate( {"top": "+="+item_size}, speed, 'linear', function(){alert();});

Change linear to whatever easing function you need.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文