Version: 1.1, Last updated: 3/14/2010
jQuery resize event | Version: 1.1, Last updated: 3/14/2010 |
License | Copyright © 2010 “Cowboy” Ben Alman, Dual licensed under the MIT and GPL licenses. |
Examples | This working example, complete with fully commented code, illustrates a few ways in which this plugin can be used. |
Support and Testing | Information about what version or versions of jQuery this plugin has been tested with, what browsers it has been tested in, and where the unit tests reside (so you can test it yourself). |
Release History | |
Properties | |
jQuery. | The numeric interval (in milliseconds) at which the resize event polling loop executes. |
jQuery. | Throttle the native window object resize event to fire no more than once every jQuery.resize.delay milliseconds. |
Events | |
resize event | Fired when an element’s width or height changes. |
Copyright © 2010 “Cowboy” Ben Alman, Dual licensed under the MIT and GPL licenses. http://benalman.com/about/license/
This working example, complete with fully commented code, illustrates a few ways in which this plugin can be used.
resize event | http://benalman.com |
Information about what version or versions of jQuery this plugin has been tested with, what browsers it has been tested in, and where the unit tests reside (so you can test it yourself).
jQuery Versions | 1.3.2, 1.4.1, 1.4.2 |
Browsers Tested | Internet Explorer 6-8, Firefox 2-3.6, Safari 3-4, Chrome, Opera 9.6-10.1. |
Unit Tests | http://benalman.com |
Throttle the native window object resize event to fire no more than once every jQuery.resize.delay milliseconds. Defaults to true.
Because the window object has its own resize event, it doesn’t need to be provided by this plugin, and its execution can be left entirely up to the browser. However, since certain browsers fire the resize event continuously while others do not, enabling this will throttle the window resize event, making event behavior consistent across all elements in all browsers.
While setting this property to false will disable window object resize event throttling, please note that this property must be changed before any window object resize event callbacks are bound.
Fired when an element’s width or height changes. Because browsers only provide this event for the window element, for other elements a polling loop is initialized, running every jQuery.resize.delay milliseconds to see if elements’ dimensions have changed. You may bind with either .resize( fn ) or .bind( “resize”, fn ), and unbind with .unbind( “resize” ).
jQuery('selector').bind( 'resize', function(e) { // element's width or height has changed! ... });
While this plugin works in jQuery 1.3.2, if an element’s event callbacks are manually triggered via .trigger( ‘resize’ ) or .resize() those callbacks may double-fire, due to limitations in the jQuery 1.3.2 special events system. This is not an issue when using jQuery 1.4+.
// While this works in jQuery 1.4+ $(elem).css({ width: new_w, height: new_h }).resize(); // In jQuery 1.3.2, you need to do this: var elem = $(elem); elem.css({ width: new_w, height: new_h }); elem.data( 'resize-special-event', { width: elem.width(), height: elem.height() } ); elem.resize();