JavaScript 中 onresize 事件有什麼用?
當視窗大小改變時,則觸發 resize 事件。在 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>
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言
C++
C#
MongoDB
MySQL
Javascript
PHP