davesmiths
4/9/2014 - 2:40 PM

Buffer/Throttle triggered events (js)

Buffer/Throttle triggered events (js)

var delay = 200
    ,run
    ,runBuffer
;

run = function() {
    console.log('resize event fired');
};

// Prevent unnecessary calls to run
runBuffer = function() {
    clearTimeout(tid);
    tid = setTimeout(function() {
        run();
    }, delay);
};

$(window).on('resize', runBuffer);
//$(window).on('scroll', runBuffer);