I am just trying to execute some code when the scroll bar of the page is about halfway down my page (or 500px). The issue is that this code works for going all the way to the bottom of the page to execute but if I supply numbers nothing happens when scrolling. Does anyone know how to have it so the event will execute when scrolling 500px down?
Works
$(window).scroll(function(){
if ($(window).scrollTop() == $(document).height() - $(window).height()){
Does Not
$(window).scroll(function(){
if ($(window).scrollTop() == parseInt(500)){
Do you really need to trigger that exactly at 500px? can’t you do something like
use a flag variable if you want to trigger this event just once, but keep in mind that
.scroll()is not triggered at EACH pixel the window is scrollinga flag approach can be like this