简体   繁体   English

滚动动画触发完成处理程序两次

[英]scroll animation trigger complete handler twice

This scroll animation trigger the complete handler twice.. 这个滚动动画触发整个处理程序两次..

$('html,body').stop().animate({
    scrollTop : 100
}, {
    duration : 600,
    complete : function(){
        console.log('scroll complete');
    }
});

If you remove either html or body in the selector the scroll animation loose its cross browser support... 如果在选择器中删除htmlbody ,则滚动动画会松开其跨浏览器支持...

The animation is triggered on both elements, firing the complete handler for both elements. 动画在两个元素上触发,触发两个元素的完整处理程序。

You can use a promise to avoid it 您可以使用承诺来避免它

$('html,body').stop()
              .animate({scrollTop : 100}, 600)
              .promise()
              .done(function() {
                  console.log('scroll complete');
              });

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

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