CodeLab
Show Output
 
xxxxxxxxxx
20
 
1
<!DOCTYPE html>
2
<html lang="en">
3
<head>
4
    <meta charset="utf-8">
5
    <title>JavaScript Handling the Resize Event</title>
6
</head>
7
<body>
8
    <p id="result"></p>
9
    <script>
10
        function displayWindowSize(){
11
            var w = window.outerWidth;
12
            var h = window.outerHeight;
13
            var txt = "Window size: width=" + w + ", height=" + h;
14
            document.getElementById("result").innerHTML = txt;
15
        }
16
        window.onresize = displayWindowSize;
17
    </script>
18
    <p><strong>Note:</strong> Resize the browser window to see how the resize event works.</p>
19
</body>
20
</html>
 

在微博、微信、公众号、小程序分享此示例。 如果您觉得有帮助,请给我们一个赞。