Scrolling animation trigger full handler twice

This scroll animation runs the full handler twice.

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

      

If you remove html

or in the selector body

, the scroll animation will lose cross-browser support ...

+3


source to share


1 answer


The animation runs on both elements, triggering a full handler for both elements.

You can use a promise to avoid this.



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

      

+2


source







All Articles