我正在尝试检测浏览器何时停止调整大小。以下工作,但取决于全球变量。有没有办法使用闭包来避免这种情况?如果是这样,怎么样?
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> ");
}
}
答案 0 :(得分:0)
(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> ");
}
}
})();
是一个闭包