JavaScript中onresize事件的用途是什么?
调整窗口大小时会触发调整大小事件。在调整浏览器大小时,可以在JavaScript中使用 window.outerWidth和window.outerHeight事件获取窗口的大小。
示例
您可以尝试运行以下代码以在JavaScript中处理onresize事件。
<!DOCTYPE html>
<html>
<head>
<script>
function resizeFunction() {
var val = "Window Width=" + window.outerWidth + ", Window Height=" + window.outerHeight;
document.getElementById("test").innerHTML = val;
}
</script>
</head>
<body onresize="resizeFunction()">
<p>Resize browser window and check the window (browser window) height and width again.</p>
<p id = "test"> </p>
</body>
</html>