0

So I've got the following code:

window.onload = function () {

function getScrollTop() {
    if (typeof window.pageYOffset !== 'undefined') {
        // Most browsers
        return window.pageYOffset;
    }

    var d = document.documentElement;
    if (d.clientHeight) {
        // IE in standards mode
        return d.scrollTop;
    }

    // IE in quirks mode
    return document.body.scrollTop;
}

window.onscroll = function () {
    var reviewbasket = document.getElementById('reviewbasket'),
    scroll = getScrollTop();

    if (scroll > 950) {
        $("#global").stop;
    }
    else {
        reviewbasket.style.top = (scroll + 0) + "px";
    }
};

};

Currently the scroll ends at 950 px however I wish for the div to scroll right up until the max height of either the content area (#content) or the page is reached. I also don't want the div to overlap the footer. The main problem I face is that this page is viewed in two different states: Logged in and Logged out, Logged out comes with an extra content area which pushes the basket down further and stops me being able to set a fixed height for the scroll to end.

Any tips or direction is welcome!

Thanks, Dan

4

1 に答える 1

0

コンテンツ div の高さを保持する変数を作成します。次に、ページの状態が変化したとき (ログイン => ログアウト)、関数を呼び出して高さ変数を更新します。

var maxScroll = $("#content").height();

function resetMaxScroll() {
    maxScroll = $("#content").height();
}

...

if (scroll > maxScroll) {
    $("#global").stop;
}
于 2013-04-16T13:48:32.760 に答える