Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scroll to top is not smooth enough

Tags:

jquery

i am using this script for scroll to top button:

$(document).ready(function(){
    $(".upp").click(function(){
        $('html, body').animate({scrollTop: '0px'}, 1200);
    });
});

It is going to top while being animated, but the animation is not smooth enough.it jumps at some parts, then slides to top. I even tried increasing the value from 1200 to 5000, but it scrolls while jumping at certain points. i am using simple jquery library (latest version).Do you think that adding jquery UI will solve anything? please help.

like image 473
gaurav oberoi Avatar asked Jan 26 '26 19:01

gaurav oberoi


2 Answers

I think your best bet is to utilize the easing option of .animate()

From the documentation:

Easing

The remaining parameter of .animate() is a string naming an easing function to use. An easing function specifies the speed at which the animation progresses at different points within the animation. The only easing implementations in the jQuery library are the default, called swing, and one that progresses at a constant pace, called linear. More easing functions are available with the use of plug-ins, most notably the jQuery UI suite.

$(".upp").click(function(){
    $('html, body').animate({scrollTop: '0px'}, 1200, 'linear');
});
like image 162
gvee Avatar answered Jan 28 '26 11:01

gvee


try this:

 $('html, body').animate({ scrollTop: $('.docs').offset().top}, 2000);
like image 41
Sivasailanathan Avatar answered Jan 28 '26 13:01

Sivasailanathan



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!