To wait for the end of ‘resize’ event and only then perform an action with JavaScript, we set the window.onresize
property to the resize event handler.
For instance, we write
window.onresize = () => {
console.log("resized");
};
to set window.onresize
to a function that’s called when we resize the tab or window.