jquery – smooth auto scroll by using javascript

jquery – smooth auto scroll by using javascript

Its not smooth because youve got the scroll incrementing by 50 every 100 milliseconds.

change this and the amount you are scrolling by to a smaller number to have the function run with the illusion of being much more smooth.

turn down the speed amount to make this faster or slower.

function pageScroll() {
    window.scrollBy(0,1);
    scrolldelay = setTimeout(pageScroll,10);
}

will appear to be much smoother, try it 😉

Try to use jQuery, and this code:

$(document).ready(function(){
     $(body,html).animate({scrollTop: 156}, 800); 
});

156 – position scroll to (px), from top of page.
800 – scroll duration (ms)

jquery – smooth auto scroll by using javascript

You might want to look at the source code for the jQuery ScrollTo plug-in, which scrolls smoothly. Or maybe even just use the plug-in instead of rolling you own function.

Leave a Reply

Your email address will not be published.