Last active
December 22, 2015 04:28
-
-
Save esson/6417120 to your computer and use it in GitHub Desktop.
Trigger events for 'resizestart' and 'resizeend' on $(window).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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