今天聊聊小程序的 IntersectionObserver
接口。
兼容性
基础信息:
- 文档: IntersectionObserver
- 兼容: 基础库 > 1.9.3
observeAll
: 基础库 > 2.0.0
API
通过 IntersectionObserver wx.createIntersectionObserver(Object this, Object options)
创建 IntersectionObserver
对象实例 options
可选配置有
thresholds
,触发阈值的集合数组,默认[0]
,例:我配置了[0, 0.5, 0.8]
,那么当监听对象和参照物相交比例达到0 / 0.5 / 0.8
时,会触发监听器的回调函数initialRatio
,初始相交比例,默认0
,达到initialRatio
或thresholds
中的阈值时,回调被触发obser