Created
January 27, 2015 14:21
-
-
Save vuongtran/67ca65d2b7b81a58fa01 to your computer and use it in GitHub Desktop.
Directly attaching a handler to the scroll event is considered bad practice because (depending on the browser) this event can fire many times within a few milliseconds. A solution below will be deal with this issue.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var scrollticker; | |
jQuery(window).scroll(function() { | |
if (scrollticker) { | |
window.clearTimeout(scrollticker); | |
scrollticker = null; | |
} | |
// Set Timeout | |
scrollticker = window.setTimeout(function() { | |
if (jQuery('#div-fetching').length) { | |
if (jQuery(window).scrollTop() >= jQuery('#div-fetching').offset().top + jQuery('#div-fetching').outerHeight() - window.innerHeight) { | |
//code fetching handle matrix | |
} | |
} | |
}, 500); // Timeout in msec | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment