[英]How do I lock the orientation to portrait mode in a Mobile Web Application?
I am making a web application using html, and javascript for mobile devices (phones). 我正在使用html和javascript制作用于移动设备(电话)的Web应用程序。 How can I lock the screen orientation in portrait? 如何锁定纵向屏幕? Are there any extensions, or frameworks to do this? 有任何扩展或框架可以做到这一点吗?
EDIT: When the user goes into landscape mode, I want a only a div (in the shape of a box if it matters) to be displayed that contains the text "please turn your device to portrait." 编辑:当用户进入横向模式时,我只希望显示一个div(如果重要的话,它的形状为方框),其中包含文本“请把设备转为纵向”。
You can use something like the following CSS media query: 您可以使用类似以下CSS媒体查询的内容:
@media screen and (orientation: landscape) {
.main-content { display: none; }
.use-portrait { display: block; }
}
Which would hide your main-content
and show the use-portrait
div when the device is in landscape mode. 当设备处于横向模式时,这将隐藏您的main-content
并显示use-portrait
div。 You can use some additional CSS to rotate the use-portrait
div to further entice the user to do that: 您可以使用一些其他CSS来旋转use-portrait
div,以进一步诱使用户这样做:
.use-portrait {
-webkit-transform: rotate(90deg);
transform: rotate(90deg);
}
And you may need to translate it to appear correctly. 并且您可能需要翻译它才能正确显示。
try this; 尝试这个;
$(window).on("orientationchange",function(){
event.stopPropagation();
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.