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
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.
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.
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 });
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.”
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With