JavaScript Notes

Ever Helpful Timeout code

from Alvaro Trigo
I use this little snippet constantly when customizing Responsive builds. I normally set my timeout a bit longer than 500 milliseconds, but the general idea is to reduce the frequency of running the “doneResizing” function thus reducing the load on the user’s browser.

var resizeId;
$(window).resize(function() {
clearTimeout(resizeId);
resizeId = setTimeout(doneResizing, 500);
});

function doneResizing(){
//whatever we want to do
}