Skip to content

listenWindowResize

Functions

listenWindowResize()

listenWindowResize(callback, options): Object

监听窗口大小改变事件,并触发指定回调

Parameters

ParameterTypeDescription
callback() => void监听回调
optionsListenWindowResizeOptions配置项

Returns

Object

isListening

isListening: () => boolean

是否正在监听

Returns

boolean

start

start: () => undefined | () => void

启动监听器

Returns

undefined | () => void

stop

stop: () => void

停止监听器

Returns

void

Example

ts
const { stop } = listenWindowResize(() => { console.log('窗口改变了') })
// 需要时结束监听
stop()

// 结合 `createEventHook` 使用
const resizeEvent = createEventHook()
listenWindowResize(resizeEvent.trigger)

resizeEvent.on(() => { console.log('callback1') })
resizeEvent.on(() => { console.log('callback2') })
resizeEvent.on(() => { console.log('callback3') })

Interfaces

ListenWindowResizeOptions

Properties

PropertyTypeDescription
emitOnPageShow?boolean是否在页面从隐藏转为显示时触发一次回调

Default
true
immediate?boolean是否立即启动监听器,设为 false 时需手动调用 start() 启动

Default
true
immediateCallback?boolean是否立即执行一次回调

Default
false