Call a function when the browser window is resized:
<body onresize="myFunction()">
Try it Yourself »
More "Try it Yourself" examples below.
The onresize event occurs when the browser window has been resized.
Tip: To get the size of an element, use the clientWidth, clientHeight, innerWidth, innerHeight, outerWidth, outerHeight, offsetWidth and/or offsetHeight properties.
Event | |||||
---|---|---|---|---|---|
onresize | Yes | Yes | Yes | Yes | Yes |
In JavaScript, using the addEventListener() method:
object.addEventListener("resize",
myScript);
Try it Yourself »
Bubbles: | No |
---|---|
Cancelable: | No |
Event type: | UiEvent if generated from a user interface, Event otherwise |
HTML tags: | <body> |
DOM Version: | Level 2 Events |
Using the addEventListener() method to attach the "resize" event on the window object.
window.addEventListener("resize", myFunction);
Try it Yourself »
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!