iphone方向更改后,我可以在移动Safari中触发CSS事件吗? [英] Can I trigger a CSS event in mobile safari upon iphone orientation change?

查看:95
本文介绍了iphone方向更改后,我可以在移动Safari中触发CSS事件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在试图弄清楚当用户将手机从纵向旋转到横向模式时如何更改嵌入式网页 - 基本上是为了加载更适合更宽屏幕格式的视图。这可以不从服务器调用新页面,即从CSS / Javascript本身驱动它吗?

I'm trying to figure out how to change an embedded web page when the user rotates their phone from portrait to landscape mode - basically to load a view that is better suited to the wider screen format. Is this possible to do without calling a new page from the server, i.e. to drive it from within CSS/Javascript itself?

谢谢!

推荐答案

您可以使用 window.orientation 属性。其值是使用当前模式的程度。这是一个简短的例子:

You can use the window.orientation property. Its value is the degree that the current mode of view is used. Here is a brief example:

function updateOrientation()
{   
    var orientation=window.orientation;
    switch(orientation)
    {

        case 0:

                break;  

        case 90:
                break;

        case -90:   

                break;
    }

}

你可以在这个上使用这个功能事件:

You can use this function on this event:

window.onorientationchange=updateOrientation;

希望有所帮助!

这篇关于iphone方向更改后,我可以在移动Safari中触发CSS事件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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