Open
Description
I have a real use case here: getting all IMG elements which at least 50% are displayed in the viewport at 2 seconds after the page is loaded.
setTimeout(() => {
let observer = new IntersectionObserver(entries => {
entries.forEach(entry => {
console.log(entry.target)
})
}, {
threshold: 0.5,
// once: true
})
Array.from(document.querySelectorAll("img")).forEach(item => observer.observe(item))
setTimeout(() => observer.disconnect(), 20) // a workaround.
}, 2000)