How to change the mobile orientation of mobile screen on the click of button? Like portrait view to landscape view?
Asked
Active
Viewed 6,023 times
4
-
Look this: http://www.noupe.com/design/html5-screen-orientation-api-uses-javascript-to-rotate-the-screen-89639.html – Marcos Alexandre Sedrez Nov 24 '16 at 10:58
-
This could also be helpful: http://stackoverflow.com/questions/14360581/force-landscape-orientation-mode – Pete Nov 24 '16 at 11:13
2 Answers
4
You can use -webkit-transform(CSS) property to change the orientation:
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
$('body').css({
"-webkit-transform": "rotate(90deg)"
});
}
Aniket Sahrawat
- 11,710
- 3
- 36
- 63
1
First make the body full screen. You can do it by
document.body.requestFullscreen().then(res=>console.log(res).catch(err=>console.log(err);
Then rotate it by using
screen.orientation.lock('landscape').then(res=>console.log(res)).catch(err=>console.log(err))
Note : This will work only in mobile browser. If you don't know how to use console in android chrome then please read this article Here
Tushar Upadhyay
- 61
- 4