JavaScript window resize callback with timeout

If you need to run certain functions after the user rotates the mobile device screen or manually resizes the browser window, you must prevent unnecessary calls.

I've found this short snippet will help you with that. Check it out, try the demo. Enjoy.

window-resize-javascript
var resizeWindow;
window.onresize = function() {
    clearTimeout(resizeWindow);
    resizeWindow = setTimeout(function() {
        // Do something after resize
    }, 100);
};

Demo

View Demo

About Rick

Senior Front-end Software Engineer from Barcelona, Haidong Gumdo Instructor (korean martial art of the sword), street photographer, travel lover, TV addict, Boston Red Sox fan, and privacy advocate.
2 comments

Leave a Reply

Add <code> Some Code </code> by using this tags.

*
*