page-observer
v1.0.3
Published
页面滚动监听
Downloads
5
Readme
页面滚动监听
使用方式:
let pgWatch = new PageObserver() // 初始化实例
/* 开始监听
* document.querySelectorAll('.img'): 要监听的元素集合
* name 表示每个标签上的唯一区分属性比如id, name等
* _ => console.log('cb') 表示监听时的回调
* 最后的数字 表示回调的触发类型
* 0: 解除监听前触发
* 1: 被监听元素进入可视区就触发
* 2: 被监听元素首次离开可视区被触发
**/
pgWatch.watch(document.querySelectorAll('.img'), 'name', _ => console.log('cb'), 0)
pg.unWatch() // 解除监听