【技术支持】关于html中移动端innerwidth的问题

首先看问题

移动端web相关

屏幕是375*667

html 复制代码
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <!-- <meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=0" /> -->
        <meta name="viewport" content="width=device-width, initial-scale=2.0" />
        <title>Document</title>
        <style>
            * {
                margin: 0;
            }
            #test {
                height: 100px;
                background-color: aquamarine;
            }
        </style>
    </head>
    <body>
        <div id="test"></div>
        <script>
            let div = document.getElementById("test");
            console.log(window.innerWidth); //375
            console.log(document.documentElement.clientWidth); //375
            div.style.width = 970 + "px";
            console.log(window.innerWidth); //971
            console.log(document.documentElement.clientWidth); //375
        </script>
    </body>
</html>

此代码在桌面端正常,在移动端有些异常,移动端的window.innerWidth不是视口大小,会变化

解决办法就是<meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=0" />,添加user-scalable=0

相关推荐
孔令飞3 分钟前
Go中指针引用Go中指针引用Go中指针引用Go中指针引用Go中指针引用Go中指针引用Go中指针引用Go中指针引用Go中指针引用Go中指针引用Go中指针引用Go中
前端
可乐鸡翅yeah_9 分钟前
hls.js 缓冲区参数 maxBufferLength、maxBufferSize 通俗讲解与业务调参
开发语言·javascript·ios·音视频·safari·m3u8
溪语流沙16 分钟前
【Web全栈进阶】PostgreSQL上手:Docker跑库 + 把早报站从SQLite迁过去
前端·docker·postgresql
IT_陈寒21 分钟前
SpringBoot自动配置的坑:你以为的捷径可能是弯路
前端·人工智能·后端
paopaokaka_luck21 分钟前
高校社团管理(AI辅助任务分配、协同过滤算法推荐、ECharts数据可视化、活动参与闭环、校园交流与反馈、器材借还管理)
java·前端·javascript·spring boot·数据分析·echarts
听风34727 分钟前
windplay网页创意实验场
css·html·创意·website·windplay
5008438 分钟前
React Native for OpenHarmony 实战:三方库 react-native-volume-control 的鸿蒙化适配指南
javascript·react native·react.js·electron·harmonyos
薛一半41 分钟前
React-Redux三重优化实战揭秘
javascript·vue.js·react.js
Dovis(誓平步青云)1 小时前
导览音频切换太快,旧讲解不能覆盖新展品
android·前端·javascript·ecmascript·音视频·宠物
福兮说11 小时前
设计稿是 #4A7C6F,页面量出来是 #4B7C6F:HEX、HSL、透明度、canvas 来回转的七个坑
前端·javascript·css·canvas