简体   繁体   English

jQuery动画在运行时触发两次回调

[英]jQuery animation triggers callback twice when run

I'm animating a scroll to effect using jQuery, after the animation ends, I trigger an effect, for some reason the effect is triggered twice, how can I prevent it from happening? 我正在使用jQuery动画滚动效果,在动画结束后,我触发效果,由于某种原因,效果被触发两次,我该如何防止它发生?

$('.something').on('click', function() {
            $('html, body').animate({
                scrollTop: $('footer').offset().top
            }, {
                queue: false,
                duration: 1500,
                complete: function() {
                    $('.foo').toggleClass('active');
                    $('.bar').slideToggle();    
                }
            });                
            return false;
        });

The slideToggle effect seems to be triggered twice. slideToggle效果似乎被触发了两次。 I have it animate on html & body because animate from 'body' doesn't work in IE8. 我在html和body上设置了动画,因为来自'body'的动画在IE8中不起作用。

Since you're triggering two animations (on html and body) the complete callback should be called twice. 由于您正在触发两个动画(在html和body上),因此应该调用两次完整的回调。

You might want to on trigger the animation on html only if it's required 您可能希望仅在需要时才在html上触发动画

var animateOn = isIE8 ? 'html' : 'body';
$(animateOn).animate();

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

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