关于android:移动端如何强制横屏

4次阅读

共计 631 个字符,预计需要花费 2 分钟才能阅读完成。

因为刚开始没有思路,找了很多大神的参考,最初了解的出如下:
思路:在竖屏状态下,让 body 旋转成横屏,宽高获取屏幕的宽高;

<body>
<div id="print">
<h3>Mlll000999887</h3>
</div>
</body>

css 写法:

竖屏变横屏,body 的宽高还是不对,当初用 js 来计算:

第二种办法:
1. 通过增加监听事件 onorientationchange,而后判断 window.orientation 这个参数

window.orientation 参数对应的屏幕方向:Andriod:0 或 180 横屏

Andriod:90 或 -90 竖屏

ipad,iphone:90 或 -90 横屏

ipad,iphone:0 或 180 竖屏
  1. window.matchMedia(“(orientation: portrait)”) 办法
    返回的是一个 MediaQueryList 对象,matches 值为 true 示意为竖屏, 反之就是横屏:
安卓手机在某些浏览器中能够禁止页面横屏:QQ 和微信中浏览器:<meta name="x5-orientation" content="portrait">
UC 浏览器:<meta name="screen-orientation" content="portrait">

最初:
当然不止这一种办法,也能够全靠 css 来实现;

最初感激博主大神:https://cloud.tencent.com/dev…
https://blog.csdn.net/Lc_styl…

正文完
 0