猿问

打印screnn.width的问题

https://img3.mukewang.com/5c28685000018a5213260786.jpg

<!doctype html>

<html>

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=300"/>

    <title>Document</title>

</head>

<body>


    <script>

        console.log(window.screen.width);

    </script>

    

</body>

</html>


墨色风雨
浏览 467回答 1
1回答

慕工程0101907

首先screen.width 就是你这个设备的宽度,你看一下我的代码和结果结局&nbsp;<!doctype html><html><head>&nbsp; &nbsp; <meta charset="UTF-8">&nbsp; &nbsp; <meta name="viewport" content="width=300"/>&nbsp; &nbsp; <title>Document</title></head><body>&nbsp; &nbsp; <script>&nbsp; &nbsp; &nbsp; &nbsp; console.log(window.screen.width);&nbsp; &nbsp; </script>&nbsp; &nbsp;&nbsp;</body></html>结果看到了吗,再看这一段代码还有这个结果 ,明白了吗?你的<meta name="viewport" content="width=300"/>只是改变的是viewport的宽度,并不是设备的屏幕宽度,设备的屏幕宽度理论上是更改不了的。viewport的解释详情请点击这里,讲的很详细,虽然我大多数情况下是直接拉倒最后,但是还是坚持看完了
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答