Mobile site - force landscape only / no auto-rotate

后端 未结 5 2234
梦如初夏
梦如初夏 2020-11-27 16:53

I have a site that has a mobile stylesheet:


I\'m also using jQue

5条回答
  •  盖世英雄少女心
    2020-11-27 17:29

    You can't force orientation in web page, but you can suggest or block content in portarit mode.

    I made a adaptation of a existing script

    in your html file add a div element

    Turn your device in landscape mode.

    Then adapt your css to cover all your page

    #block_land{position:absolute; top:0; left:0; text-align:center; background:white; width:100%; height:100%; display:none;}
    

    Then add a litle javascript to detect orientation

    function testOrientation() {
      document.getElementById('block_land').style.display = (screen.width>screen.height) ? 'none' : 'block';
    }
    

    Don't forget to test the orientation in the onload and onorientationchange, maybe in your body tag

    
    

    Let me know if this solution works for you.

提交回复
热议问题