2013-03-04 71 views
1

我正在制作一个单页网站,我想在第二部分显示导航菜单直到结束。我发现这个问题: Change CSS class after scrolling 1000px down滚动屏幕高度降低100%后更改CSS类

...和我使用的答案AlienWebguy

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

但我不想做1000像素。我想用它100%的屏幕,它可以用不同的平台或分辨率来改变。

你知道我能做什么吗?

+0

只要找出有多大的屏幕,并使用,而不是1000 – 2013-03-04 16:01:18

+0

可能重复的[滚动1000px下来后更改CSS类](http://stackoverflow.com/questions/12470645/change-css-class-后滚动-1000像素下) – johnc 2013-03-05 01:50:08

回答

1

使用此:

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

}); 
0

您可以$(window).height()

取代1000如:

$(document).scroll(function() { 
    $('#menu').toggle($(this).scrollTop()>$(window).height()) 
}); 
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 
    } 
}); 

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