Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 784
clarkk Avatar asked Jul 12 '26 20:07

clarkk


1 Answers

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');
              });
like image 141
adeneo Avatar answered Jul 14 '26 10:07

adeneo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!