当 iPhone 方向改变时,我可以在 mobile 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?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可以使用
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:You can use this function on this event:
Hope that helps!
最好不要直接设置
onorientationchange
属性。而是使用以下内容:Best not to set the
onorientationchange
property directly. Instead use the following:我不敢相信没有人谈论 CSS 裁决:
I can't believe no one talked about the css ruling:
Safari 移动浏览器支持
orientationchange
事件以及窗口上的orientation
属性,因此您可以执行以下操作:我会添加颠倒是因为 iPad 人机界面指南规定您应该支持所有方向,因此我希望 iPad 上的 Safari(可能还有未来的 iPhone 版本)能够支持它。
The Safari mobile browser has support for the
orientationchange
event as well as theorientation
property on the window, so you can do something like:I would add the upside-down because the iPad human interface guidelines say you should support all orientations, so I would expect Safari on the iPad (and possibly future iPhone versions) to support it.
Safari Mobile 支持 定向事件。
Safari Mobile supports orientation events.
来自:Safari 网页内容指南
From: Safari Web Content Guide