How do I make the javascript resize event handler happen only after the user stops resizing the window? I don't want it to get called over and over again as the user is resizing the window.
$(window).resize(function () {
if( document.getElementById('staticImage').style.display == 'table-cell') {
resizeWithImageMap();
} else {
resizeWithoutImageMap();
}
});
Thanks.
Adeneo posted a nice functional example, but I'm partial to building it all into my own handler:
var resizeComplete = (function() {
var funcs = [];
var timer ;
var delay = 250;
window.onresize = function() {
window.clearTimeout(timer);
timer = window.setTimeout(function() {
for (var i = 0; i < funcs.length; i++) {
funcs[i](); // Call the func
}
}, delay);
};
function register(func) {
funcs.push(func);
}
return {
register: register
}
}());
resizeComplete.register(function() {
console.log("Resize complete");
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.