仅仅是一个vue plugin和一个指令
使用IntersectionObserver(不阻塞主线程),不支持IntersectionObserver 使用scroll+函数节流+setTimeout
严格测试
# install with npm
npm install vue-intersection-plugin
# install with yarn
yarn add vue-intersection-plugin
import vueIntersectionPlugin from "vue-intersection-plugin";
Vue.use(vueIntersectionPlugin, {
handler: (logData)=> {
// your logic code
},
duration: 3000, //在页面可视区域停留时长
// threshold: []
});
// add directive
<YourComponent>
<div
v-intersection
:data-log="JSON.stringify({
//your log data
})"
>
</div>
</YourComponent>