How to set viewport meta for iPhone that handles rotation properly?

前端 未结 9 1703
情话喂你
情话喂你 2020-11-27 10:11

So I\'ve been using:


to get my HTML c

相关标签:
9条回答
  • 2020-11-27 10:31

    just want to share, i've played around with the viewport settings for my responsive design, if i set the Max scale to 0.8, the initial scale to 1 and scalable to no then i get the smallest view in portrait mode and the iPad view for landscape :D... this is properly an ugly hack but it seems to work, i don't know why so i won't be using it, but interesting results

    <meta name="viewport" content="user-scalable=no, initial-scale = 1.0,maximum-scale = 0.8,width=device-width" />
    

    enjoy :)

    0 讨论(0)
  • 2020-11-27 10:37

    You don't want to lose the user scaling option if you can help it. I like this JS solution from here.

    <script type="text/javascript">
    (function(doc) {
    
        var addEvent = 'addEventListener',
            type = 'gesturestart',
            qsa = 'querySelectorAll',
            scales = [1, 1],
            meta = qsa in doc ? doc[qsa]('meta[name=viewport]') : [];
    
        function fix() {
            meta.content = 'width=device-width,minimum-scale=' + scales[0] + ',maximum-scale=' + scales[1];
            doc.removeEventListener(type, fix, true);
        }
    
        if ((meta = meta[meta.length - 1]) && addEvent in doc) {
            fix();
            scales = [.25, 1.6];
            doc[addEvent](type, fix, true);
        }
    
    }(document));
    </script>
    
    0 讨论(0)
  • 2020-11-27 10:40

    Was just trying to work this out myself, and the solution I came up with was:

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

    This seems to lock the device into 1.0 scale regardless of it's orientation. As a side effect, it does however completely disable user scaling (pinch zooming, etc).

    0 讨论(0)
  • 2020-11-27 10:42

    I have come up with a slighly different approach that should work on cross platforms

    http://www.jqui.net/tips-tricks/fixing-the-auto-scale-on-mobile-devices/

    So far I have tested in on

    Samsun galaxy 2

    • Samsung galaxy s
    • Samsung galaxy s2
    • Samsung galaxy Note (but had to change the css to 800px [see below]*)
    • Motorola
    • iPhone 4

      • @media screen and (max-width:800px) {

    This is a massive lip forward with mobile development ...

    0 讨论(0)
  • 2020-11-27 10:46
    <meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1">
    

    suport all iphones, all ipads, all androids.

    0 讨论(0)
  • 2020-11-27 10:47

    You're setting it to not be able to scale (maximum-scale = initial-scale), so it can't scale up when you rotate to landscape mode. Set maximum-scale=1.6 and it will scale properly to fit landscape mode.

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