Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find out if ipad is in landscape/portrait mode in javascript/jquery?

I want to add an extra div if the ipad is in landscape mode. Is there some sort of if statement that could find this out?

Thanks

like image 392
cat Avatar asked Aug 16 '10 17:08

cat


People also ask

How do you tell if an image is landscape or portrait Javascript?

You can simply compare width and height of the image. var someImg = $("#someId"); if (someImg. width() > someImg. height()){ //it's a landscape } else if (someImg.

How do I know what orientation my device is?

You can detect this change in orientation on Android as well as iOS with the following code: var supportsOrientationChange = "onorientationchange" in window, orientationEvent = supportsOrientationChange ? "orientationchange" : "resize"; window.

How do I get orientation in Javascript?

Detecting Orientation Changes in Javascript Should you need to simply detect when a user changes orientation, you can use the following event listener: screen. orientation. addEventListener("change", function(e) { // Do something on change });

How do you tell if an image is landscape or portrait?

The length of the longest side determines the orientation. For example, if the height of the image is longer than the width, it is a “portrait” format. Images where the width is longer are called “landscape.”


1 Answers

jQTouch checks it like so:

orientation = Math.abs(window.orientation) == 90 ? 'landscape' : 'portrait';

http://github.com/senchalabs/jQTouch/blob/master/jqtouch/jqtouch.js

You can also listen to onorientationchange events

See previous answer: Detect rotation of Android phone in the browser with JavaScript

like image 73
edtechdev Avatar answered Nov 15 '22 07:11

edtechdev