Try the following:
function throttle( fn, timeout ) { var tid = 0; return function() { clearTimeout( tid ); var args = [].slice.call( arguments ), ctx = this; tid = setTimeout( function() { fn.apply( ctx, args ); }, timeout ); }; } $(window).on("scroll", throttle( function() { $('div').eq(0).append('scroll happened'); }, 100));
It will only trigger scrolling as soon as scrolling does not occur in 100 milliseconds.
http://jsfiddle.net/NLGHS/1/
Esailija
source share