I'm trying to detect when the browser has stopped being resized. The following works, but depends on global vars. Isn't there a way to use closures to avoid this? If so, how?开发者_如何学Go
var rtime = new Date(1, 1, 2000, 12,00,00);
var timeout = false;
var delta = 200;
$(document).ready(function() {
$(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;
$("#log").append("<span>resizeend</span> ");
}
}
** Script credit: http://vidasp.net/resizeend.html
(function(){
var rtime = new Date(1, 1, 2000, 12,00,00);
var timeout = false;
var delta = 200;
$(document).ready(function() {
$(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;
$("#log").append("<span>resizeend</span> ");
}
}
})();
Is a closure
精彩评论