如何使用javascript或Jquery更改屏幕方向? [英] How can i change Screen Orientation using javascript or Jquery?
问题描述
我正在使用Android和iPhone的Phonegap开发一个应用程序。当我从一个页面导航到另一个页面时,我需要更改屏幕方向。
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 it can be done through either java script or jquery ?
谢谢
推荐答案
您可以尝试:
$(window).resize(function() {
var height = $(window).height();
var width = $(window).width();
if (width > height) {
// Landscape
$("#mode").text("LANDSCAPE");
} else {
// Portrait
$("#mode").text("PORTRAIT");
}
});
另一个id window.orientation
0
, 90
或 -90
其中:
Another one id window.orientation
which return 0
, 90
or -90
where:
-
0
代表:肖像模式
90
代表:横向模式,屏幕向左转
90
stands for: landscape mode with the screen turned to the left
-90
代表:横向模式,屏幕向右转
-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;
}
}
您还可以查看
使用javascript 在浏览器中检测Android手机的旋转信息。
Detect rotation of Android phone in the browser with javascript for info.
这篇关于如何使用javascript或Jquery更改屏幕方向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!