Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I typically use the <code>orientationchange</code>event to add / remove CSS classes to the content, and go from there, rather than re-size the viewport. Apple provide some stand-alone example code, although from memory I think that it only includes 90° and 0° orientations—you need -90° and 180° too, as in @zyrex comment.</p> <p><a href="http://developer.apple.com/library/safari/#samplecode/iPhoneOrientation/Introduction/Intro.html#//apple_ref/doc/uid/DTS10004520" rel="nofollow noreferrer">iPhoneOrientation sample code (developer.apple.com)</a></p> <p><strong>Update per comment:</strong> To clarify, I don't re-size HTML entities themselves, rather change the classes being used, and rely on CSS to style accordingly. To take a simplistic example, say I want to switch between two classes on the <code>body</code> element, depending on device orientation, I would do something like this in my Javascript:</p> <pre><code>window.onorientationchange = updateOrientation; // (Might want to do this onload too) function updateOrientation(){ var o = window.orientation, body = document.querySelector('body'); switch(o){ case 0: case 180: body.className = 'portrait'; break; case 90: case -90: body.className = 'landscape'; break; } } </code></pre> <p>… and something like this in the default mark-up:</p> <pre><code>&lt;body class="portrait"&gt; &lt;!-- stuff here --&gt; </code></pre> <p>… and then CSS which does whatever is required—e.g. a different position for the body element's <code>background</code>:</p> <pre><code>body {background: url('images/something.png') no-repeat} body.portrait {background-position: 30% 50%} body.landscape {background-position: 10% 25%} </code></pre> <p><strong>Update #2</strong> You may also need to tinker with the <code>maximum-scale</code> directive in your meta tag. Mobile Safari typically does a zoom when changing from portrait to landscape, instead of re-doing the page layout, and that may be what you're seeing.</p> <p>The <code>maximum-scale</code> value prevents this, but you should note that this also means users can't do the normal pinch-to-zoom thing. Here's how the tag would look:</p> <pre><code>&lt;meta name="viewport" content="initial-scale=1, maximum-scale=1"&gt; </code></pre> <p>Be sure to check the answers here too:</p> <p><a href="https://stackoverflow.com/questions/2557801/how-do-i-reset-the-scale-zoom-of-a-web-app-on-an-orientation-change-on-the-iphone">How do I reset the scale/zoom of a web app on an orientation change on the iPhone?</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload