简体   繁体   中英

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...

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');
              });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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