title: Taro.getWindowInfo()

sidebar_label: getWindowInfo

获取窗口信息

支持情况:Taro.getWindowInfo() - 图1 Taro.getWindowInfo() - 图2 Taro.getWindowInfo() - 图3

H5: 不支持 statusBarHeight、safeArea

参考文档

类型

  1. () => Result

参数

Result

参数 类型 必填 说明
pixelRatio number 设备像素比
screenWidth number 屏幕宽度,单位px
screenHeight number 屏幕高度,单位px
windowWidth number 可使用窗口宽度,单位px
windowHeight number 可使用窗口高度,单位px
statusBarHeight number 状态栏的高度,单位px
safeArea TaroGeneral.SafeAreaResult 在竖屏正方向下的安全区域

示例代码

  1. const windowInfo = Taro.getWindowInfo()
  2. console.log(windowInfo.pixelRatio)
  3. console.log(windowInfo.screenWidth)
  4. console.log(windowInfo.screenHeight)
  5. console.log(windowInfo.windowWidth)
  6. console.log(windowInfo.windowHeight)
  7. console.log(windowInfo.statusBarHeight)
  8. console.log(windowInfo.safeArea)
  9. console.log(windowInfo.screenTop)