如何使用javascript或Jquery更改屏幕方向?
我正在使用Phonegap for Android和iphone开发应用程序。 当我从一个页面导航到另一个页面时,我需要更改屏幕方向。 谁能说出如何通过java脚本或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
返回window.orientation
或-90
其中:
-
0
代表:肖像模式 -
90
代表:横向模式,屏幕向左转 -
-90
代表:横向模式,屏幕向右转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手机在浏览器中的旋转信息。