Skip to content

Instantly share code, notes, and snippets.

@eccentricpixel
Created December 27, 2014 06:02
Show Gist options
  • Save eccentricpixel/e241328a9e3483b6227a to your computer and use it in GitHub Desktop.
Save eccentricpixel/e241328a9e3483b6227a to your computer and use it in GitHub Desktop.
Do something when window has stopped resizing; after user has finished dragging window. This is more efficient than just using .resize() which will fire thing incrementally while the user may still be dragging.
var rtime = new Date(1, 1, 2000, 12,00,00);
var timeout = false;
var delta = 200;
$(window).resize(function() {
rtime = new Date();
if (timeout === false) {
timeout = true;
setTimeout(resizeend, delta);
}
});
function resizeend() {
if (new Date() - rtime < delta) {
setTimeout(resizeend, delta);
} else {
timeout = false;
// do something
var curWinWidth = $(window).width();
if ( curWinWidth < 1810) {
// do something
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment