(1)可用高度:減去頂部底部的工具欄的高度
window.screen.availWidth
返回當(dāng)前屏幕寬度(空白空間) window.screen.availHeight
返回當(dāng)前屏幕高度(空白空間)
(2)屏幕寬度:不關(guān)瀏覽器或者頂部底部工具欄的高度,在微信里出除去頭部和底部的bar的高度和寬度。在手機(jī)端,可以獲取手機(jī)屏幕的邏輯分辨率
window.screen.width
返回當(dāng)前屏幕寬度(分辨率值) window.screen.height
返回當(dāng)前屏幕高度(分辨率值)
(3)客戶端高度:瀏覽器里面整個(gè)頁(yè)面的高度
document.body.clientHeight
(4)可見(jiàn)可用高度
document.documentElement.clientHeight
:瀏覽器里面頁(yè)面的可用可見(jiàn)高度。
window.document.body.offsetHeight;
返回當(dāng)前網(wǎng)頁(yè)高度 window.document.body.offsetWidth;
返回當(dāng)前網(wǎng)頁(yè)寬度
在<head>中引入 <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> 棵里,不加這句,移動(dòng)端都返回980赠法。加上這句侧纯,PC和移動(dòng)端都能正確獲取。
設(shè)備寬度 var diviceWidth = document.documentElement.clientWidth;
設(shè)備高度 var diviceHeight = document.documentElement.clientHeight;
這樣就可以獲取到手機(jī)的分辨率了墩新,比如iphone4 320*480
上面的說(shuō)法是不正確的哲鸳,如果是在微信里打開(kāi)網(wǎng)頁(yè)郁岩,獲取到的寬度和高度不是手機(jī)的邏輯分辨率,高度比邏輯分辨率里的高度小,因?yàn)闇p去了頂部和底部的bar片酝。
(1)可用高度:減去頂部底部的工具欄的高度
window.screen.availWidth
返回當(dāng)前屏幕寬度(空白空間) window.screen.availHeight
返回當(dāng)前屏幕高度(空白空間)
(2)屏幕寬度:不關(guān)瀏覽器或者頂部底部工具欄的高度审轮,在微信里出除去頭部和底部的bar的高度和寬度崖飘。在手機(jī)端,可以獲取手機(jī)屏幕的邏輯分辨率
window.screen.width
返回當(dāng)前屏幕寬度(分辨率值) window.screen.height
返回當(dāng)前屏幕高度(分辨率值)
(3)客戶端高度:瀏覽器里面整個(gè)頁(yè)面的高度
document.body.clientHeight
(4)可見(jiàn)可用高度
document.documentElement.clientHeight
:瀏覽器里面頁(yè)面的可用可見(jiàn)高度。
window.document.body.offsetHeight;
返回當(dāng)前網(wǎng)頁(yè)高度 window.document.body.offsetWidth;
返回當(dāng)前網(wǎng)頁(yè)寬度
在<head>中引入 <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> ,不加這句酥泞,移動(dòng)端都返回980。加上這句,PC和移動(dòng)端都能正確獲取。
設(shè)備寬度 var diviceWidth = document.documentElement.clientWidth;
設(shè)備高度 var diviceHeight = document.documentElement.clientHeight;
這樣就可以獲取到手機(jī)的分辨率了,比如iphone4 320*480
上面的說(shuō)法是不正確的,如果是在微信里打開(kāi)網(wǎng)頁(yè)栽燕,獲取到的寬度和高度不是手機(jī)的邏輯分辨率付秕,高度比邏輯分辨率里的高度小亮元,因?yàn)闇p去了頂部和底部的bar。
(5)手機(jī)的物理分辨率:
<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="" cid="n18" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; background-position: inherit inherit; background-repeat: inherit inherit;">window.screen.width * window.devicePixelRatio</pre>
物理分辨率,又叫物理尺寸批销。是指屏幕的實(shí)際大小掀宋。大的屏幕同時(shí)必須要配備高分辨率,也就是在這個(gè)尺寸下可以顯示多少個(gè)像素,顯示的像素越多,可以表現(xiàn)的余地自然越大。
(5)手機(jī)的物理分辨率:
<pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang="" cid="n18" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9em; display: block; break-inside: avoid; text-align: left; white-space: normal; background-image: inherit; background-size: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(248, 248, 248); position: relative !important; border: 1px solid rgb(231, 234, 237); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; padding: 8px 4px 6px; margin-bottom: 15px; margin-top: 15px; width: inherit; background-position: inherit inherit; background-repeat: inherit inherit;">window.screen.width * window.devicePixelRatio</pre>
物理分辨率陶贼,又叫物理尺寸。是指屏幕的實(shí)際大小。大的屏幕同時(shí)必須要配備高分辨率楼肪,也就是在這個(gè)尺寸下可以顯示多少個(gè)像素,顯示的像素越多爷速,可以表現(xiàn)的余地自然越大毙石。