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
2 Answers
Reset to default 3You 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条)