在javascript中使用iPad的方向 [英] Working with orientation of the iPad in javascript

查看:164
本文介绍了在javascript中使用iPad的方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用iPad中的方向。我使用手机差距来构建应用程序。
我已经为方向更改完成了以下代码:

I am working with the orientation in iPad . I am using phone gap for building the application. I have done following code for orientation change :

       function updateOrientation() 
        {
            var orientation=window.orientation;
            if ( orientation == 0 ) {
                alert("Do Something In Portrait Mode");
            }
            else if ( orientation == 90 ) {
                alert("Do Something In landscape Mode");
            }
            else if ( orientation == -90 ) {
                alert("Do Something In Portrait Mode");
            }
            else if ( orientation == 180 ) {
                alert("Do Something In landscape Mode");
            }               
        }

我收到警报,但我不知道如何调整窗口里面的大小?可以有人帮助我吗?我想要如下:

I am getting the alerts but I don't know how to resize the window inside this ? Can anybody help me ?I want like following :

推荐答案

Safari和Android都支持简单的方向更改事件侦听器。

Both Safari and Android support a simple orientation change event listener.

<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=320; user-scalable=no" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>PhoneGap</title>
     <script type="text/javascript" charset="utf-8" src="phonegap-1.1.0.js"></script>
     <script type="text/javascript" charset="utf-8" src="main.js"></script>

</head>
<body onload="init();" >

    <h2>Orientation Test</h2>
    <div id="status"></div>

</body>
</html>

和js代码:

function init() {
    window.addEventListener("orientationchange", orientationChange, true);
}

function orientationChange(e) {
    var orientation="portrait";
    if(window.orientation == -90 || window.orientation == 90) orientation = "landscape";
        document.getElementById("status").innerHTML+=orientation+"<br>";
}

来源

这篇关于在javascript中使用iPad的方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆