返回值:jQueryresize(handler(eventObject))
Bind an event handler to the "resize" JavaScript event, or trigger that event on an element.
-
1.0 新增resize(handler(eventObject))
handler(eventObject) (Function) 每当事件触发时执行的函数。 -
1.4.3 新增resize([eventData], handler(eventObject))
eventData (Object) 可选参数,将要传递给事件处理函数的数据映射。handler(eventObject) (Function) 每当事件触发时执行的函数。 -
1.0 新增resize()
This method is a shortcut for .bind('resize', handler)
in the first variation, and .trigger('resize')
in the second.
The resize
event is sent to the window
element when the size of the browser window changes:
$(window).resize(function() { $('#log').append('<div>Handler for .resize() called.</div>'); });
Now whenever the browser window's size is changed, the message is appended to <div id="log"> one or more times, depending on the browser.
Code in a resize
handler should never rely on the number of times the handler is called. Depending on implementation, resize
events can be sent continuously as the resizing is in progress (the typical behavior in Internet Explorer and WebKit-based
browsers such as Safari and Chrome), or only once at the end of the resize operation (the typical behavior in Firefox).
示例:
To see the window width while (or after) it is resized, try:
jQuery 代码:
$(window).resize(function() {
$('body').prepend('<div>' + $(window).width() + '</div>');
});