jQuery在两个动画之间的延迟 [英] jQuery delay between two animations

查看:113
本文介绍了jQuery在两个动画之间的延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码:

   $("#telecomGrayscale", this).stop().animate({ top: '467px' }, 
    { duration: 400 }).delay(800).queue(function() {
                $("#boxcaptionTelecom", this).stop().animate({ top: '272px' }, { duration: 900 });
                });

上面的代码无法按需工作.队列()中的第二个动画不是 工作.

我只需要延迟第二个动画.还尝试了setTimeout和setInterval无法使它们工作.

解决方案

在第二个动画中,this不是您想的那样,因此以this作为上下文的选择器很可能为空./p>

尝试一下是否可行

var self = this;
$("#telecomGrayscale", self)
    .stop()
    .animate(
        { top: '467px' },
        { duration: 400 }
    )
    .delay(800)
    .queue(
        function() {
            $("#boxcaptionTelecom", self)
                .stop()
                .animate(
                    { top: '272px' },
                    { duration: 900 }
                );
            return $(this).dequeue();
        }
    );

Code:

   $("#telecomGrayscale", this).stop().animate({ top: '467px' }, 
    { duration: 400 }).delay(800).queue(function() {
                $("#boxcaptionTelecom", this).stop().animate({ top: '272px' }, { duration: 900 });
                });

The above code is not working as needed. The 2nd animation that is inside the queue () is not working.

I just need to delay the second animation. Also tried setTimeout and setInterval could not get them to work.

解决方案

In your second animation, the this is not what you think it is, so the selector with this as a context is most likely empty.

Try if this works:

var self = this;
$("#telecomGrayscale", self)
    .stop()
    .animate(
        { top: '467px' },
        { duration: 400 }
    )
    .delay(800)
    .queue(
        function() {
            $("#boxcaptionTelecom", self)
                .stop()
                .animate(
                    { top: '272px' },
                    { duration: 900 }
                );
            return $(this).dequeue();
        }
    );

这篇关于jQuery在两个动画之间的延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆