Skip to content

Instantly share code, notes, and snippets.

@esson
Last active December 22, 2015 04:28
Show Gist options
  • Select an option

  • Save esson/6417120 to your computer and use it in GitHub Desktop.

Select an option

Save esson/6417120 to your computer and use it in GitHub Desktop.
Trigger events for 'resizestart' and 'resizeend' on $(window).
/**
* jQuery.resize.events.js
*
* Trigger events for 'resizestart' and 'resizeend' on $(window).
* @param {Number} timeoutms Defines the time in milliseconds before the 'resizeend' event is triggered.
*
* Version: 1.0
* Author: Martin Eriksson
*/
(function ($, timeoutms) {
var timeout;
$(window).on('resize', function (event, width, height) {
if (timeout) {
clearTimeout(timeout);
} else {
$(window).trigger('resizestart', [width, height]);
}
timeout = setTimeout(function () {
$(window).trigger('resizeend', [width, height]);
timeout = null;
}, timeoutms);
});
})(jQuery, 300);
// Additional Console Test
//
$(window).on('resizestart resizeend', function (event, width, height) {
console.log(event.type + ' at ' + width + 'x' + height);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment