为防止低版本不兼容,安装插件'intersection-observer'
import 'intersection-observer'
export const exposureMPing = (_list = [], _pageEventId, page_id, _key) => {
try {
const handleCallback = (entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
let params = {
page_id
}
if (_key) {
params = {...params, json_param: {[_key]: entry.target[_key]}}
}
clickMPing(_pageEventId, params)
obserRefs.unobserve(entry.target)
}
})
}
const opstion = {
root: null,
rootMargin: '0px',
threshold: [0.25]
}
const obserRefs = new IntersectionObserver(handleCallback, opstion)
_list.length && _list.forEach(item => obserRefs.observe(item))
} catch (err) {
console.log('曝光埋点手机版本不兼容')
}
}