使用javascript连续滚动页面 [英] Continuous scrolling page using javascript

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

问题描述

我正在尝试重复一个页面自动滚动到底部的动画.当它到达底部时,我希望它滚动到顶部.然后,永远重复.但是,我什至无法执行第一个回调.任何帮助将不胜感激.

I am trying to repeat an animation where a page automatically scrolls to the bottom. When it reaches the bottom I want it to then scroll to the top. Then, repeat forever. However, I can't get it to even perform the first callback. Any help would be greatly appreciated.

代码:

pageScroll(pageScrollUp);





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

    callback(pageScroll);

}


function pageScrollUp(callback) {

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

    callback(pageScrollUp);

}

谢谢乔希

推荐答案

应该这样做:http://jsfiddle.net/John_C/8ZfKr/

var scrollDirection = 1;
function pageScroll() {
    window.scrollBy(0,scrollDirection); // horizontal and vertical scroll increments
    scrolldelay = setTimeout('pageScroll()',50); // scrolls every 50 milliseconds
    if ( (window.scrollY === 0) || (window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
        scrollDirection = -1*scrollDirection;
    }
}
pageScroll();

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

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