You need to trigger an event if the page scrolls 200 pixels down (jQuery)

I want to show and hide a piece of code, if I scroll the page, for example, halfway, I tried to use window scrolling, but it doesn’t work (no errors, clean code, different browsers, different versions of jQuery), but it doesn’t start anything, so I looking for a better way to show and hide the div if I view the scroll.

used this to trigger an event (not working)

$(window).scroll(function(){
    alert('works')
});
+3
source share
1 answer

Try using the window.onload function (which they use in jQuery examples):

window.onload = (function(){
  $(window).scroll(function () { 
    if( $(window).scrollTop() > 200 ) {
      // Display something
    }
  })
})
+3
source

All Articles