【问题标题】:how to calculate width and height of mobile device如何计算移动设备的宽度和高度
【发布时间】:2012-04-08 11:51:31
【问题描述】:

我想在 document.body 下创建一个 div。 该 div 的宽度和高度应该是这样的 它完全适合移动设备,现在该设备可以 像 ipad 这样的平板电脑或像 iPhone 这样的移动设备,或任何网页 桌面浏览器。 我尝试使用 screen.width 和 screen.height,但这些值不是 完全等于设备的宽度和高度! 然后凭经验我尝试从中减去一些数字,得到18 当 div 的宽度和高度 = sreen.width 和 screen.height 时,避免在 document.body 上滚动。 但即使是这个数字也不是在所有浏览器上都一致。

我还有一个问题,在 iPhone 上,如果我们将视图从纵向更改为横向, 为什么字体大小会改变? 我在 html 页面上有这个元标记

【问题讨论】:

    标签: css ios html android-layout web-applications


    【解决方案1】:

    尝试使用PHP browser detection library

    它提供了大量关于操作系统、浏览器等的信息。

    【讨论】:

      【解决方案2】:

      你可以使用 jQuery:

      var w = $(document).width();
      var h = $(document).height();
      //your div, for example with class 'loremIpsum', will get exactly that sizes with:
      $('div.loremIpsum').width(w).height(h);
      

      【讨论】:

        猜你喜欢
        • 2017-02-08
        • 2017-05-31
        • 2020-06-25
        • 1970-01-01
        • 2014-07-27
        • 2015-12-16
        • 2023-04-01
        • 2012-09-04
        • 1970-01-01
        相关资源
        最近更新 更多