<img class="ob" v-for="item in f1" style="width: 150px; height: 150px; margin-right: 10px" :data-src="item"></img>
let obs = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.src = entry.target.dataset.src;
obs.unobserve(entry.target)
}
});
},
{
root: null,//指定观察元素的父节点,默认为视口
rootMargin: "0px",//父节点的偏移量
threshold: 0.5,//被观察元素的相对视口的偏移量
}
);
document.querySelectorAll(".ob").forEach((el) => {
obs.observe(el);
});
IntersectionObserver
最新推荐文章于 2024-07-11 17:37:13 发布