本文介绍了检测视口方向,如果方向是纵向显示警告消息,建议用户说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立专门针对移动设备的网站。特别是有一个页面,最好以横向模式查看。

I am building a website specifically for mobile devices. There is one page in particular which is best viewed in landscape mode.

有没有办法检测访问该页面的用户是否在纵向模式下查看它,如果是,则显示一条消息,通知用户该页面在景观模式?如果用户已在横向模式下查看,则不会显示任何消息。

Is there a way to detect if the user visiting that page is viewing it in Portrait mode and if so, display a message informing the user that the page is best viewed in landscape mode? If the user is already viewing it in landscape mode then no message will appear.

所以基本上,我希望网站检测视口方向,如果方向是纵向,然后显示一条提示消息,告知用户此页面最佳浏览横向模式。

So basically, I want the site to detect the viewport orientation, if orientation is Portrait, then display an alert message advising the user that this page is best viewed in Landscape mode.

非常感谢,
Dan

Many thanks,Dan

推荐答案

if(window.innerHeight > window.innerWidth){
    alert("Please use Landscape!");
}

jQuery Mobile有一个事件处理此属性的更改...如果如果有人稍后轮换,你想发出警告 -

jQuery Mobile has an event that handles the change of this property... if you want to warn if someone rotates later - orientationchange

此外,在一些谷歌搜索后,查看 window.orientation (我相信以度数衡量...

Also, after some googling, check out window.orientation (which is i believe measured in degrees...

这篇关于检测视口方向,如果方向是纵向显示警告消息,建议用户说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 21:07