简体   繁体   English

动画后的jQuery延迟

[英]jQuery Delay After Animation

I currently have a jQuery animation attached to a back button and I'm using the bind command to prevent the next page from loading before the animation completes. 我目前在后退按钮上附加了一个jQuery动画,并且我正在使用bind命令来防止动画完成之前加载下一页。 Sadly even with the bind command the animation still gets cut off pretty quickly.Is there any way to ensure the animation plays entirely or a way to add a delay or pause after the animation yet before the next page load? 不幸的是,即使使用bind命令,动画仍然会很快被切断。是否有任何方法可以确保动画完全播放,或者是否可以在动画之后但在下一页加载之前增加延迟或暂停?

Heres my jQuery: 这是我的jQuery:

    $(document).ready(function () {
        $(".back").click(function () {
            $(".back")
                .addClass('magictime vanishOut')
                .bind("animationend webkitAnimationEnd oAnimationEnd MSAnimationEnd", function () {});
        });

});

I'm going to bet the page transition is the default action of the back element's click event. 我敢打赌,页面转换是back元素的click事件的默认操作。 You need to prevent the default action and then fire off the page transition in the animation end callback. 您需要阻止默认操作,然后在动画结束回调中触发页面过渡。

$(document).ready(function () {
    $(".back").click(function (e) {
        e.preventDefault();
        $(".back")
            .addClass('magictime vanishOut')
            .bind("animationend webkitAnimationEnd oAnimationEnd MSAnimationEnd",
            function () {
                // TODO fire off the page transition
            }
        );
    });
});

Let me know how it works. 让我知道它是如何工作的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM