También sería importante usar un temporizador https://developer.mozilla.org/en-US/docs/Web/Events/resize#setTimeout ya que es muy costosa la modificación del DOM.
(function() {
window.addEventListener("resize", resizeThrottler, false);
var resizeTimeout; function resizeThrottler() { // ignore resize events as long as an actualResizeHandler execution is in the queue if ( !resizeTimeout ) { resizeTimeout = setTimeout(function() { resizeTimeout = null; actualResizeHandler();
// The actualResizeHandler will execute at a rate of 15fps
}, 66);
}
(function() {
window.addEventListener("resize", resizeThrottler, false);
var resizeTimeout;
function resizeThrottler() {
// ignore resize events as long as an actualResizeHandler execution is in the queue
if ( !resizeTimeout ) {
resizeTimeout = setTimeout(function() {
resizeTimeout = null;
actualResizeHandler();
// The actualResizeHandler will execute at a rate of 15fps
}, 66);
}
}
function actualResizeHandler() {
// handle the resize event
...
}
}());
}
function actualResizeHandler() { // handle the resize event ... }
}());