IntersectionObserver's callback function was not called
P粉052724364
P粉052724364 2023-08-15 20:15:03
0
1
427
<p>I have a cross viewer. Everything works fine. I have a top section. But when I scroll down and then refresh (it refreshes to the previously visible section), the cross-viewer callback is called to the top section instead of the visible section. </p> <pre class="brush:php;toolbar:false;">const observerCallBack = (entries, observer) => { const [entry] = entries console.log("Callback:",entry.target) if(!entry.isIntersecting) return; if(entry.target.children.length > 1){ entry.target.children[1].classList.remove('slide-from-right') entry.target.children[0].classList.remove('slide-from-left') }else{ entry.target.classList.remove('slide-from-left') } observer.unobserve(entry.target) } const observeOptions = { root:null, threshold:[0.5, 0.9], } const observer = new IntersectionObserver(observerCallBack,observeOptions)</pre> <p>I've tried using console.log but didn't find any solution. </p>
P粉052724364
P粉052724364

reply all(1)
P粉366946380

You need to subscribe to the observer you are creating by providing it with the element you want to observe.

observer.observe(this.elementRef.nativeElement);
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template