Chinchan Zu
Chinchan Zu

Reputation: 918

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.

Upvotes: 4

Views: 10560

Answers (3)

Sliq
Sliq

Reputation: 16504

Most simple answer: Get the orientation (at any time in your js code) via

window.orientation

When window.orientation returns 0 or 180 then you are in portrait mode, when returning 90 or 270 then you are in landscape mode.

Upvotes: 1

moimikey
moimikey

Reputation: 35

I would take into consideration this post:

http://www.matthewgifford.com/2011/12/22/a-misconception-about-window-orientation/

Upvotes: 1

Hupperware
Hupperware

Reputation: 979

$(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

Upvotes: 8

Related Questions