开发者

Can you hide an html div with jQuery/Javascript when the page is scrolled to a certain number of pixels?

开发者 https://www.devze.com 2023-03-23 20:37 出处:网络
I hav开发者_JAVA百科e a div that is fixed position that I want hidden once the page is scrolled to a certain position. Is there any way to do this with jQuery/Javascript? Yep, something like this shou

I hav开发者_JAVA百科e a div that is fixed position that I want hidden once the page is scrolled to a certain position. Is there any way to do this with jQuery/Javascript?


Yep, something like this should do the trick:

var max_scroll = 300;
$(document).scroll(function(){
  if($(this).scrollTop() >= max_scroll)
  {
      $('#my_div').fadeOut();
  }
});


$(document).scroll(function(){
    if($(document).scrollTop()>100){
        $("#myElement").hide();
    }
}

edit: Oop, I see someone already posted a working solution,

0

精彩评论

暂无评论...
验证码 换一张
取 消