Is there a way to prevent $(window).scroll() from firing on page load?
Testing the following code in Firefox 4, it fires even when I unplug the mouse.
jQuery(document).ready(function($){
$(window).scroll(function(){
console.log("Scroll Fired");
});
});
The
scrollevent is unrelated to the mouse, it is called whenever a new document scrolling position is set. And arguably that position is set when the document loads (you might load it with an anchor after all), also if the user presses a cursor key on his keyboard. I don’t know why you need to ignore the initialscrollevent but I guess that you only want to do it ifpageYOffsetis zero. That’s easy:Note: MSIE doesn’t have
window.pageYOffsetproperty so the above will need to be adjusted. Maybe jQuery offers a cross-browser alternative.