Intersection Observerを使ってみた。
javascript
const targetEle = document.querySelector(".targetEle");
const cb = function (entries, observer) {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add("inview")
} else {
entry.target.classList.remove("inview")
}
})
}
const io = new IntersectionObserver(cb, options);
io.observe(targetEle)
ーーーーーーーーーーーーーーーーーーーーーーーーーーー
参考