问题描述
我有一个带有一个大水平 div 的网站.它会在加载时自动垂直和水平滚动(我使用这里讨论的 javascript:smooth auto scroll by使用 javascript):
I have a website with one big horizontal div. It automatically scrolls vertically and horizontally onload (I used this javascript as discussed here: smooth auto scroll by using javascript):
function pageScroll() {
window.scrollBy(10,-10); // horizontal and vertical scroll increments
scrolldelay = setTimeout('pageScroll()',100); // scrolls every 100 milliseconds
}
我想知道但不知道的是:是否可以切换此功能?我希望当页面自动滚动到页面末尾时,它会再次向上和向左返回.这样它就来来回回,永远上下.
What I would like to know but can't figure out: is it possible to toggle this function? I would like that once the page automatically scrolled to the end of the page, that it goes back up and back to the left again. So that it goes back and forth, up and down forever.
非常感谢所有帮助,提前致谢!
All help is very appreciated, thanks in advance!
推荐答案
Working Fiddle http://jsfiddle.net/sajith/MJQ7u/
Working Fiddle http://jsfiddle.net/sajith/MJQ7u/
var xMax, yMax, xNeg=1, yNeg=1;
function pageScroll() {
window.scrollBy(10 * xNeg, 10 * yNeg);
if(xMax == window.scrollX)xNeg = xNeg * -1;
if(yMax == window.scrollY)yNeg = xNeg * -1;
scrolldelay = setTimeout(pageScroll,100);
console.log(window.scrollY);
xMax = window.scrollX;
yMax = window.scrollY;
}
这篇关于如何切换自动滚动功能/反向页面滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!