Skip to content

Instantly share code, notes, and snippets.

@imelgrat
Last active August 23, 2017 19:53
Show Gist options
  • Save imelgrat/736bd9fec263b7b60374 to your computer and use it in GitHub Desktop.
Save imelgrat/736bd9fec263b7b60374 to your computer and use it in GitHub Desktop.
Prevent jerky motion upon resizing browser window by waiting until window resizing stops (no external libraries). Full article at: http://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