I'm trying to use the function _.debounce() of underscore.js but I can't do it properly.
I'm trying to debounce the scroll of my window as shown below, but I am seriously confused.
$(document).ready(function () {
$(window).scroll(function (event) {
var scrollCounter = $(this).scrollTop();
if ( scrollCounter > 0 ) { //do stuff }
else { //do stuff }
});
});
From the documentation and example:
you can refactor your call to debounce it like this:
Update: Working jsfilddle: https://jsfiddle.net/z635f7ys/