自动获取屏幕尺寸信息的html文件

html 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>自动获取屏幕尺寸信息的html文件</title>
    <style>
        #testDiv {
            width: 100%;
            height: 100vh; /* 100% of the viewport height */
            background-color: lightblue;
            text-align: center;
            font-size: 2em;
            display: flex;
            justify-content: center;
            align-items: center;
        }
    </style>
</head>
<body>
    <div id="testDiv">
        宽度: <span id="width"></span>px, 高度: <span id="height"></span>px
    </div>

    <script>
        function updateSize() {
            const div = document.getElementById('testDiv');
            const width = div.offsetWidth;
            const height = div.offsetHeight;
            document.getElementById('width').textContent = width;
            document.getElementById('height').textContent = height;
        }

        window.onload = updateSize;
        window.onresize = updateSize;
    </script>
</body>
</html>
相关推荐
英俊潇洒美少年18 分钟前
vue如何实现react useDeferredvalue和useTransition的效果
前端·vue.js·react.js
kyriewen111 小时前
给浏览器画个圈:CSS contain 如何让页面从“卡成PPT”变“丝滑如德芙”
开发语言·前端·javascript·css·chrome·typescript·ecmascript
英俊潇洒美少年1 小时前
react19和vue3的优缺点 对比
前端·javascript·vue.js·react.js
~无忧花开~3 小时前
React生命周期全解析
开发语言·前端·javascript·react.js·前端框架·react
哈__3 小时前
ReactNative项目OpenHarmony三方库集成实战:react-native-maps
javascript·react native·react.js
cj81403 小时前
Prompt,Agent,Skill,Mcp分别于langchain有什么关系
前端
SuperEugene4 小时前
Axios + Vue 错误处理规范:中后台项目实战,统一捕获系统 / 业务 / 接口异常|API 与异步请求规范篇
前端·javascript·vue.js·前端框架·axios
行走的陀螺仪4 小时前
手写 Vue3 极简 i18n
前端·javascript·vue.js·国际化·i18n
羽沢314 小时前
一篇简单的STOMP教程QAQ
前端·javascript·stomp