发生一定量的滚动时隐藏元素

在滚动N个像素后,我只想在页面上隐藏一个元素。

$(window).scroll(function(){ if($(document).scrollTop() > 200){ $('.fixedelement').css({'display': 'none'}); } }); 

我认为这可能会有效,并且在200px的滚动后,.fixedelement会消失。 唉,它不起作用。 有什么想法吗?

这似乎工作正常: http : //jsfiddle.net/maniator/yDVXY/

 $(window).scroll(function() { if ($(this).scrollTop() > 200) { //use `this`, not `document` $('.fixedelement').css({ 'display': 'none' }); } }); 

试试这个。

 $(window).scroll(function(){ if($(document).scrollTop() > 200){//Here 200 may be not be exactly 200px $('.fixedelement').hide(); } });