Appearance
onIntersectionObserve
▸ onIntersectionObserve(options
, cb
): void
监听元素
参数
Name | Type | Default value | Description |
---|---|---|---|
options | Object | undefined | |
options.margins | any | undefined | 距离参照物边距 |
options.observer | any | null | 自定义 IntersectionObserver 实例 |
options.relativeToSelector | any | undefined | 指定参照节点,不传默认参照页面 |
options.selector | string | undefined | 元素选择器 |
cb | [intersectionRatio: number, res: any] | undefined | observe 回调函数 |
返回值
void
示例
ts
onIntersectionObserve(
{
selector: '.card',
margins: {bottom: 100},
},
intersectionRatio => {
visible.value = intersectionRatio === 0
}
)
// 更多参数
const observer = createIntersectionObserver(getCurrentInstance(), {
thresholds: [0, 1],
initialRatio: 1,
})
onIntersectionObserve(
{
selector: '.card',
relativeToSelector: '.container',
margins: {bottom: 100},
observer: observer,
},
intersectionRatio => {
visible.value = intersectionRatio === 0
}
)