Skip to content

Instantly share code, notes, and snippets.

@ZellSnippets
Created October 17, 2013 09:41
Show Gist options
  • Save ZellSnippets/7022014 to your computer and use it in GitHub Desktop.
Save ZellSnippets/7022014 to your computer and use it in GitHub Desktop.
JS: window resize event
// Simple debouncer.
// https://github.com/louisremi/jquery-smartresize
function on_resize(c, t) {
onresize = function() {
clearTimeout(t);
t = setTimeout(c, 100)
};
return c
};
// use like this:
on_resize(function() {
// do stuff
})();
// More complicated one.
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;
// Done resizing
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment