How to wait for the ‘end’ of ‘resize’ event and only then perform an action?

You can use setTimeout() and clearTimeout()

function resizedw(){
    // Haven't resized in 100ms!
}

var doit;
window.onresize = function(){
  clearTimeout(doit);
  doit = setTimeout(resizedw, 100);
};

Code example on jsfiddle.

Leave a Comment