为什么手机上的document.documentElement.clientWidth是980px

she*_*wen 7 viewport responsive-design

我正在尝试了解documentElement.clientWidth他们window.innerWidth在各种设备上的行为。我使用这个http://67.20.67.232/test.html页面进行测试,令我困惑的是,在我的Nexus 6上documentElement.clientWidth是980,我用开发工具的移动模拟进行了尝试,结果是相同的。那为什么是980呢?并且,在移动设备上,可以window.innerWidth考虑视口宽度吗?页面的HTML如下:

<html>
    <head>
     <script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
    <script type="text/javascript">
        (function loop(){
            requestAnimationFrame(function(){
                $('#doc').html( document.documentElement.clientWidth );
                $('#win').html( window.innerWidth );
                $('#d1').html($('#w div:eq(0)').width());
                $('#d2').html($('#w div:eq(2)').width());
                loop();
            })
        })();
    </script>
    </head>
    <body>
        <div id="w" style="margin-top:50px;margin-left:50px;font-size:50px">
            <div style="float:left">client:<span id="doc"></span></div>
            <div style="clear:both"></div>
            <div style="float:left">window:<span id="win"></span></div>
            <div style="clear:both"></div>
            <div id="d1"></div>
            <div id="d2"></div>

        </div>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

tan*_*dar 9

在 head 部分包含视口元标记:

    <meta name="viewport" content="width=device-width, initial-scale=1">
Run Code Online (Sandbox Code Playgroud)

http://developer.mozilla.org/en/docs/Mozilla/Mobile/Viewport_meta_tag

否则,大多数移动设备会假设它是桌面站点并模拟更大的视口(通常为 980 像素)。