Created
October 17, 2013 09:41
-
-
Save ZellSnippets/7022014 to your computer and use it in GitHub Desktop.
JS: window resize event
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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