How do I find the virtual viewport/screen width using Javascript?

前端 未结 3 1785
无人及你
无人及你 2021-01-02 09:39

Is there a consistent way to determine the width of the screen and virtual viewport for mobile devices using Javascript? My target platforms are mobile Safari and Android\'

相关标签:
3条回答
  • 2021-01-02 10:10

    Another StackOverflow question has this as a workaround:

    setTimeout(YourFunction, 200);
    

    And if you want the details, you can read about the bug in the issue tracker. You're experiencing a bug that exists in Android 2.2 and 2.3.

    0 讨论(0)
  • 2021-01-02 10:11

    It may help to set the scale of the viewport to 1.0 using this <meta> tag:

    <meta name="viewport" content="initial-scale=1.0; minimum-scale=1.0; maximum-scale=1.0;"/>
    

    This solved a similar problem for me when when I was creating a responsive HTML/CSS layout for a mobile app (I was using CSS @media queries).

    0 讨论(0)
  • 2021-01-02 10:23

    You can find out the various viewport widths by accessing the following link on the device

    http://ipad.atwebpages.com/viewport.html

    This would work for both desktop and mobile browsers..

    Just to add, viewport is mainly useful for mobile devices only...

    0 讨论(0)
提交回复
热议问题