How can i change Screen Orientation using javascript or Jquery?

前端 未结 1 527
没有蜡笔的小新
没有蜡笔的小新 2021-01-23 00:32

I am developing a application using Phonegap for Android and iphone. I need to change the screen orientation when i am navigating from one page to another. Can any one tell how

相关标签:
1条回答
  • 2021-01-23 01:11

    You can try this:

    $(window).resize(function() {
        var height = $(window).height();
        var width = $(window).width();
    
        if (width > height) {
            // Landscape
            $("#mode").text("LANDSCAPE");
        } else {
            // Portrait
            $("#mode").text("PORTRAIT");
        }
    
    });
    

    Another one id window.orientation which return 0, 90 or -90 where:

    • 0 stands for: portrait mode

    • 90 stands for: landscape mode with the screen turned to the left

    • -90 stands for: landscape mode with the screen turned to the right

       window.onorientationchange = function() 
      {
      var orientation = window.orientation;
      switch(orientation) {
          case 0:
              //Top side up.
              break; 
      
          case -90:
              //Left side up (turned 90 degrees to the right)
              break;
      
          case 90: 
              //Right side up (turned 90 degrees to the left)
              break;
        }
      }
      

    You can also see

    Detect rotation of Android phone in the browser with JavaScript for info.

    0 讨论(0)
提交回复
热议问题