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

前端 未结 4 1260
春和景丽
春和景丽 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条回答
  •  抹茶落季
    2021-01-01 02:13

    you can try the solution, compatible with all browser.

    Following is orientationchange compatibility pic: therefore, I author a orientaionchange polyfill, it is a based on @media attribute to fix orientationchange utility library——orientationchange-fix

    window.addEventListener('orientationchange', function(){
     if(window.neworientation.current === 'portrait|landscape'){
        // do something……
     } else {
        // do something……
     }
    }, false);
    

    and then, you can retrieve current state of orientation by window.neworientation.current and initial state of orientation by window.neworientation.init.

提交回复
热议问题