4

How to change the mobile orientation of mobile screen on the click of button? Like portrait view to landscape view?

Aniket Sahrawat
  • 11,710
  • 3
  • 36
  • 63
Bharat Negi
  • 497
  • 3
  • 12

2 Answers2

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