Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Debouncing JavaScript events to prevent jerky action
/**
* Debounce window-resize events
*
* Debouncing JavaScript events to prevent jerky action during UI changes.
*
* @link https://imelgrat.me/javascript/debouncing-javascript-events/
*/
$(window).bind('resize', function(e)
{
window.resizeEvt;
$(window).resize(function()
{
clearTimeout(window.resizeEvt);
window.resizeEvt = setTimeout(function()
{
if($(window).width() != previous_width)
{
//Do your stuff here
console.log('Resized finished.');
}
}, 250);
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.