smooth auto scroll by using javascript

六月ゝ 毕业季﹏ 提交于 2019-11-27 21:35:25

It's not smooth because you've 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 ;)

Antonix

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)

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.

Smoothly running animations depends on the clients machine. No matter how fairly you code, you will never be satisfied the way your animation runs on a 128 MB Ram system.

Here is how you can scroll using jQuery:

$(document).scrollTop("50");

You might also want to try out AutoScroll Plugin.

Dany Maor

you can use jfunc function to do this. use jFunc_ScrollPageDown and jFunc_ScrollPageUp function. http://jfunc.com/jFunc-Functions.aspx.

Since you've tagged the question as 'jquery', why don't you try something like .animate()? This particular jquery function is designed to smoothly animate all sorts of properties, including numeric CSS properties as well as scroll position.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!