onresize 特性为 GlobalEventHandlers interface is an EventHandler 处理 resize 事件。

resize event fires after the window has been resized.

句法

window.onresize = functionRef;
					

functionRef is a function name or a 函数表达式 . The function receives a FocusEvent object as its sole argument.

范例

Window size logger

<p>Resize the browser window to fire the <code>resize</code> event.</p>
<p>Window height: <span id="height"></span></p>
<p>Window width: <span id="width"></span></p>
					
const heightOutput = document.querySelector('#height');
const widthOutput = document.querySelector('#width');
function resize() {
  heightOutput.textContent = window.innerHeight;
  widthOutput.textContent = window.innerWidth;
}
window.onresize = resize;
					

规范

规范 状态 注释
HTML 实时标准
The definition of 'onresize' in that specification.
实时标准

浏览器兼容性

The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
onresize Chrome 45 Edge 12 Firefox Yes IE Yes Opera 32 Safari Yes WebView Android 45 Chrome Android 45 Firefox Android Yes Opera Android 32 Safari iOS Yes Samsung Internet Android 5.0

图例

完整支持

完整支持

另请参阅

元数据

  • 最后修改: