移動端判斷手機橫豎屏狀態

2021-07-24 20:56:13 字數 922 閱讀 9519

在做移動端開發的時候,在html頁面head中加入如下**

name="viewport"

content="width=device-width, user-scalable=no, initial-scale=1"/>

設定螢幕寬度為裝置寬度,禁止使用者手動調整縮放,頁面初始縮放程度為1

1.寫在同乙個css檔案中

@media screen and (orientation: portrait)

@media screen and (orientation: landscape)

2.分開寫在2個css中

豎屏:

rel="stylesheet"

media="all and (orientation:portrait)"

href="portrait.css">

橫屏:

rel="stylesheet"

media="all and (orientation:landscape)"

href="landscape.css">

//判斷手機橫豎屏狀態:  

window.addeventlistener("onorientationchange"

inwindow ? "orientationchange" : "resize", function()

if (window.orientation === 90 || window.orientation === -90 )

}, false);

//移動端的瀏覽器一般都支援window.orientation這個引數,通過這個引數可以判斷出手機是處在橫屏還是豎屏狀態。

移動端判斷手機橫豎屏狀態

在做移動端開發的時候,在html頁面head中加入如下 設定螢幕寬度為裝置寬度,禁止使用者手動調整縮放,頁面初始縮放程度為1 1.寫在同乙個css檔案中 media screen and orientation portrait media screen and orientation landsc...

js判斷移動端橫豎屏狀態

function hengshuping if window.orientation 90 window.orientation 90 相容寫法 window.addeventlistener onorientationchange in window orientationchange resiz...

android判斷手機螢幕橫豎屏

在乙個activity顯示中判斷當前螢幕橫豎屏情況有幾種方法 configuration configuration getresources getconfiguration if configuration.orientation configuration.orientation landsc...