使用javascript平滑自动滚动 [英] smooth auto scroll by using javascript

查看:151
本文介绍了使用javascript平滑自动滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的网页上实现一些代码,以便在加载页面后自动滚动。我使用Javascript函数执行自动滚动,并在页面加载时调用了我的函数,但页面仍然没有顺利滚动!有没有办法顺利自动滚动页面?

I am trying to implement some code on my web page to auto-scroll after loading the page. I used a Javascript function to perform auto-scrolling, and I called my function when the page loads, but the page is still not scrolling smoothly! Is there any way to auto scroll my page smoothly?

这是我的Javascript函数:

Here is my Javascript function:

function pageScroll() {
        window.scrollBy(0,50); // horizontal and vertical scroll increments
        scrolldelay = setTimeout('pageScroll()',100); // scrolls every 100 milliseconds
}


推荐答案

这并不顺利,因为你的滚动每100毫秒增加50个。

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 ;)

这篇关于使用javascript平滑自动滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆