# uni.onWindowResize(CALLBACK)

Listen for window size change events

1.6.0 Added

Platform Difference Description

App H5 微信小程序 支付宝小程序 百度小程序 抖音小程序 飞书小程序 QQ小程序
x x x

CALLBACK parameter description

Attribute Type Description
size Object The size of the changed window, the unit is px, {windowWidth,windowHeight}

code example

const windowResizeCallback = (res) => {
  console.log('变化后的窗口宽度=' + res.size.windowWidth)
  console.log('变化后的窗口高度=' + res.size.windowHeight)
}
uni.onWindowResize(windowResizeCallback)

TIPS

  • If the soft keyboard pop-up method is set to adjustResize on the App side, this event will be triggered when the keyboard pops up.
  • This event will be triggered when the screen is switched between landscape and portrait.

# uni.offWindowResize(CALLBACK)

Cancel listening window size change event

1.6.0 Added

Explanation of Platform Differences

App H5 微信小程序 支付宝小程序 百度小程序 抖音小程序 飞书小程序
x x x

Tips

  • CALLBACK is the CALLBACK passed in when calling uni.onWindowResize

code example

uni.offWindowResize(windowResizeCallback)