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

时间:2011-07-25 18:41:44

标签: jquery animation scroll

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

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

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

2 个答案:

答案 0 :(得分:8)

这似乎工作得很好:http://jsfiddle.net/maniator/yDVXY/

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

答案 1 :(得分:3)

试试这个。

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