Tuesday, April 16, 2013

Ben Alman » jQuery throttle / debounce: Sometimes, less is more!

Ben Alman » jQuery throttle / debounce: Sometimes, less is more!: "function log( event ) {
02.
console.log( $(window).scrollTop(), event.timeStamp );
03.
};
04.

05.
// Console logging happens on window scroll, WAAAY more often
06.
// than you want it to.
07.
$(window).scroll( log );
08.

09.
// Console logging happens on window scroll, but no more than
10.
// once every 250ms.
11.
$(window).scroll( $.throttle( 250, log ) );
12.

13.
// Note that in jQuery 1.4+ you can unbind by reference using
14.
// either the throttled function, or the original function.
15.
$(window).unbind( 'scroll', log );"

'via Blog this'