Search code examples
jquery-mobiledevice-orientation

jquerymobile: determine device orientation


$(window).bind("orientationchange", function(e){
   var ow = (e.orientation=="portrait" ? "縦" : "横");
   alert("端末の向きは "+ow+" です。");
});

using the above code, i could determine if the device is in portrait or landscape mode. But my question is, is it possible to determine which side on the landscape (landscape right/ landscape left) is the device tilted, also if the device is upsidedown?

thanks guys for the support.


Solution

  • $(window).bind('orientationchange', function() {
       alert(window.orientation);
    });
    
    • 0 = Portrait orientation. This is the default value
    • -90 = Landscape orientation with the screen turned clockwise
    • 90 = Landscape orientation with the screen turned counterclockwise
    • 180 = Portrait orientation with the screen turned upside down