javascript - How do I lock the orientation to portrait mode in a Mobile Web Application? - Stack Overflow

I am making a web application using html, and javascript for mobile devices (phones). How can I lock th

I am making a web application using html, and javascript for mobile devices (phones). 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."

I am making a web application using html, and javascript for mobile devices (phones). 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."

Share Improve this question edited Apr 29, 2015 at 14:22 StevenZ asked Apr 29, 2015 at 14:04 StevenZStevenZ 7,1235 gold badges18 silver badges19 bronze badges 2
  • 1 take a look at this other question: stackoverflow./questions/3501510/… – rvandoni Commented Apr 29, 2015 at 14:06
  • There is event to detect orientationChange. However locking the screen resolution is not a right option for a responsive website. Better handle it – Praveen Commented Apr 29, 2015 at 14:06
Add a ment  | 

2 Answers 2

Reset to default 3

You can use something like the following CSS media query:

@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. You can use some additional CSS to rotate the use-portrait div to further entice the user to do that:

.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();
}); 

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745280013a4620234.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信