Lock orientation

Out of context: Reply #4

  • Started
  • Last post
  • 4 Responses
  • utopian0

    iPhone Viewport Orientation

    The iPhone supports both landscape and portrait views. You can specify CSS based on viewport orientation which you determine via javascript and update the orient attribute of the body element. Target the browser with body[orient="landscape"] or body[orient="portrait"]

    iPhone ViewPort Orientation JavaScript

    The following javascript snippet detects and sets the iPhone’s viewport orientation by evaluating the innerWidth property of the window object and setting the orient attribute of the body element at regular intervals:

    var updateLayout = function() {
    if (window.innerWidth != currentWidth) {
    currentWidth = window.innerWidth;
    var orient = (currentWidth == 320) ? "profile" : "landscape";
    document.body.setAttribute("orie... orient);
    window.scrollTo(0, 1);
    }
    };

    iPhone.DomLoad(updateLayout);
    setInterval(updateLayout, 500);

View thread