查找页面的最大滚动位置

15 浏览
0 Comments

查找页面的最大滚动位置

我将页面的高度调整为200%,以适应屏幕的两倍大小。使用JavaScript,我让页面在滚动时保持滚动到顶部或底部。为此,我需要找到页面在任何浏览器或屏幕尺寸下的最低滚动点,以便在到达那里时停止滚动。

谢谢。

我的代码:(仍在完善中,还需要一些工作)

function getScrollXY() {
    var x = 0, y = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
        // Netscape
        x = window.pageXOffset;
        y = window.pageYOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        // DOM
        x = document.body.scrollLeft;
        y = document.body.scrollTop;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        // IE6 standards compliant mode
        x = document.documentElement.scrollLeft;
        y = document.documentElement.scrollTop;
    }
    return [x, y];
}
function scrollup() {
    if (xy[1] > 0) {
        window.scrollBy(0,-100);
        setTimeout(scrollup,200);
    } else {
        null;
    }
}
function scrolldown() {
    if (xy[1] < 【滚动点】) {
        window.scrollBy(0,100);
        setTimeout(scrolldown,200);
    } else {
        null;
    }
}
function dothescroll() {
    var xy = getScrollXY();
    var y = xy[1];
    setTimeout(function(){
        if (xy[1] > y) {
            scrollup();
        } else {
            scrolldown();
        }
    },200);
}

0