1

我正在制作一个单页网站,我想在第二部分显示导航菜单直到结束。我发现了这个问题: Change CSS class after scrolling 1000px down

...我使用AlienWebguy的答案

$(document).scroll(function() {
    $('#menu').toggle($(this).scrollTop()>1000)
});​ 

但我不想做1000px。我想使用它 100% 的屏幕,它可以随着不同的平台或分辨率而改变。

你知道我能做什么吗?

4

3 回答 3

1

用这个:

$(document).scroll(function() {
    var windowHeight = $(window).height();
    $('#menu').toggle($(this).scrollTop()>windowHeight)

});
于 2013-03-04T15:45:02.867 回答
0

您可以替换1000$(window).height()

如:

$(document).scroll(function() {
    $('#menu').toggle($(this).scrollTop()>$(window).height())
});
于 2013-03-04T15:45:27.533 回答
0

你可以使用它:

$(document).on("scroll", function(){
    if($(document).scrollTop() >= ($(document).height() - $(window).height())){
        //here, you're at the bottom of the page
        console.log("BOTTOM");
    } else {
        //here, you're not arrived yet
    }
});

理论上,它适用于每种屏幕尺寸。

于 2013-03-04T15:56:37.263 回答