Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can Slow down scroll to top event by jQuery animate

How can Slow down scroll to top event by jQuery animate?

$('#go-to-top').click(function() {
   $(window.opera ? 'html' : 'html, body').animate({
      scrollTop: 0
    }, 80);
});
like image 989
Tauseef Avatar asked Jan 19 '26 21:01

Tauseef


1 Answers

To slow down the scroll you can increase the time it takes to complete the animation. Currently, it's taking 80ms. If you change that number to 1 second, you can see the difference:

$('#go-to-top').click(function () {
    $(window.opera ? 'html' : 'html, body').animate({
        scrollTop: 0
    }, 1000); // scroll takes 1 second
});

Example fiddle

You can also add easing effects if you have included the jQueryUI easing library in your page.

like image 78
Rory McCrossan Avatar answered Jan 22 '26 17:01

Rory McCrossan



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!