Hide an element when a certain amount of scrolling has occured

后端 未结 2 881
南笙
南笙 2020-12-30 14:28

I\'d just like to hide an element on my page, after N number of pixels have been scrolled.

$(window).scroll(function(){
  if($(document).scrollTop() > 200         


        
相关标签:
2条回答
  • 2020-12-30 15:06

    It seems to work fine here: http://jsfiddle.net/maniator/yDVXY/

    $(window).scroll(function() {
        if ($(this).scrollTop() > 200) { //use `this`, not `document`
            $('.fixedelement').css({
                'display': 'none'
            });
        }
    });
    
    0 讨论(0)
  • 2020-12-30 15:11

    Try this.

    $(window).scroll(function(){
      if($(document).scrollTop() > 200){//Here 200 may be not be exactly 200px
        $('.fixedelement').hide();
      }
    });
    
    0 讨论(0)
提交回复
热议问题