我正在使用 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;
});
slideToggle 效果好像触发了两次。 我在 html 和 body 上设置了动画,因为来自“body”的动画在 IE8 中不起作用。
最佳答案
由于您触发了两个动画(在 html 和 body 上),因此应该调用两次完整的回调。
您可能希望仅在需要时才在 html 上触发动画
var animateOn = isIE8 ? 'html' : 'body';
$(animateOn).animate();
关于javascript - jQuery 动画在运行时触发回调两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14680038/