小程序wx.getWindowInfo
	   Object wx.getWindowInfo()
獲取窗口信息
基礎(chǔ)庫(kù) 2.20.1 開始支持,低版本需做兼容處理。
小程序插件:支持,需要小程序基礎(chǔ)庫(kù)版本不低于 2.21.3
返回值
Object
屬性    類型    說明
pixelRatio    number    設(shè)備像素比
screenWidth    number    屏幕寬度,單位px
screenHeight    number    屏幕高度,單位px
windowWidth    number    可使用窗口寬度,單位px
windowHeight    number    可使用窗口高度,單位px
statusBarHeight    number    狀態(tài)欄的高度,單位px
safeArea    Object    在豎屏正方向下的安全區(qū)域
結(jié)構(gòu)屬性    類型    說明
left    number    安全區(qū)域左上角橫坐標(biāo)
right    number    安全區(qū)域右下角橫坐標(biāo)
top    number    安全區(qū)域左上角縱坐標(biāo)
bottom    number    安全區(qū)域右下角縱坐標(biāo)
width    number    安全區(qū)域的寬度,單位邏輯像素
height    number    安全區(qū)域的高度,單位邏輯像素
screenTop    number    窗口上邊緣的y值
示例代碼
const windowInfo = wx.getWindowInfo()
console.log(windowInfo.pixelRatio)
console.log(windowInfo.screenWidth)
console.log(windowInfo.screenHeight)
console.log(windowInfo.windowWidth)
console.log(windowInfo.windowHeight)
console.log(windowInfo.statusBarHeight)
console.log(windowInfo.safeArea)
console.log(windowInfo.screenTop)
	   
 作者:大學(xué)生新聞網(wǎng)    來源:大學(xué)生新聞網(wǎng)
發(fā)布時(shí)間:2025-04-01    閱讀: