【技术支持】关于html中移动端innerwidth的问题
首先看问题
移动端web相关
屏幕是375*667
<!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
原文地址:https://blog.csdn.net/daban2008/article/details/144200607
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!