gpt4 book ai didi

javascript - 如何使用 javascript 或 Jquery 更改屏幕方向?

转载 作者:行者123 更新时间:2023-11-29 17:22:44 25 4
gpt4 key购买 nike

我正在使用适用于 Android 和 iphone 的 Phonegap 开发应用程序。当我从一页导航到另一页时,我需要更改屏幕方向。任何人都可以告诉它如何通过 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");
}

});

另一个返回 090-90 的 id window.orientation 其中:

  • 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;
    }
    }

还可以看到

Detect rotation of Android phone in the browser with JavaScript获取信息。

关于javascript - 如何使用 javascript 或 Jquery 更改屏幕方向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11572632/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com