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

前端 未结 4 1264
春和景丽
春和景丽 2021-01-01 02:04

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

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-01 02:25

    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

提交回复
热议问题