如何通过JavaScript检测iPhone何时进入横向模式?这有什么事吗? [英] How do I detect when the iPhone goes into landscape mode via JavaScript? Is there an event for this?

查看:107
本文介绍了如何通过JavaScript检测iPhone何时进入横向模式?这有什么事吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在撰写一个针对iPhone的网站。当iPhone的方向发生变化时(即当用户将手机变为横向和/或纵向模式时),我想在< body> 元素上设置课程。

I’m writing a web site targeted at the iPhone. I’d like to set a class on the <body> element when the iPhone’s orientation changes (i.e. when the user turns the phone into landscape and/or portrait mode).

我可以通过JavaScript检测到这种变化吗?是否有这样的事件?

Can I detect this change via JavaScript? Is there an event for this?

推荐答案

是的,通过 onorientationchange 事件和 window.orientation 属性。

Yup, via the onorientationchange event and the window.orientation property.

  • Documented by Apple
  • Example code on Ajaxian

这篇关于如何通过JavaScript检测iPhone何时进入横向模式?这有什么事吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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