Skip to content

Instantly share code, notes, and snippets.

@snowman-repos
Created October 3, 2012 05:28
Show Gist options
  • Save snowman-repos/3825198 to your computer and use it in GitHub Desktop.
Save snowman-repos/3825198 to your computer and use it in GitHub Desktop.

Revisions

  1. Darryl Snow renamed this gist Oct 5, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. Darryl Snow created this gist Oct 3, 2012.
    40 changes: 40 additions & 0 deletions gistfile1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    // Listen for orientation changes
    window.addEventListener("orientationchange", function() {
    // Announce the new orientation number
    alert(window.orientation);
    }, false);

    // Listen for resize changes
    window.addEventListener("resize", function() {
    // Get screen size (inner/outerWidth, inner/outerHeight)

    }, false);

    // Find matches
    var mql = window.matchMedia("(orientation: portrait)");

    // If there are matches, we're in portrait
    if(mql.matches) {
    // Portrait orientation
    } else {
    // Landscape orientation
    }

    // Add a media query change listener
    mql.addListener(function(m) {
    if(m.matches) {
    // Changed to portrait
    }
    else {
    // Changed to landscape
    }
    });

    /* portrait */
    @media screen and (orientation:portrait) {
    /* portrait-specific styles */
    }
    /* landscape */
    @media screen and (orientation:landscape) {
    /* landscape-specific styles */
    }