Skip to content

Instantly share code, notes, and snippets.

@italodr
Created March 3, 2017 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save italodr/cb7b85bae103d1c3146ad89c2c01f0d1 to your computer and use it in GitHub Desktop.
Save italodr/cb7b85bae103d1c3146ad89c2c01f0d1 to your computer and use it in GitHub Desktop.
Window width resize observer
/**
* jQuery on resize by @italo_dr (twitter) @italodr (github)
* Fix issue with iphone/ipad "resize" on height. When appears domain
* field and bottom menu.
* Add timer to launch function on resize end
*/
var timer;
var windowWidth = $(window).width();
$(window).on('resize', function(){
if ($(window).width() != windowWidth) {
windowWidth = $(window).width();
timer && clearTimeout(timer);
timer = setTimeout(function() {
/* Your function here */
}, 100);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment