Hide item when a specific scroll occurred

I just wanted to hide an element on my page, after scrolling N number of pixels.

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

I thought this might work, and after the scroll scroll through 200 pixels disappears. Alas, this does not work. Any thoughts?

+4
source share
2 answers

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

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

Try it.

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

All Articles