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.

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


View Demo

About Ricard Torres

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.

@ricard_dev @ricard_dev

📝 Blog 🎙 Podcast


Leave a Reply

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