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;
希望有所帮助!