没有调用IntersectionObserver的回调函数
P粉052724364
P粉052724364 2023-08-15 20:15:03
0
1
386
<p>我有一个交叉观察器。一切都正常工作。我有一个顶部的部分。但是当我向下滚动然后刷新(它会刷新到之前可见的部分),交叉观察器回调会被调用到顶部的部分,而不是可见的部分。</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>我已经尝试使用console.log,但没有找到任何解决方案。</p>
P粉052724364
P粉052724364

全部回复(1)
P粉366946380

您需要通过为其提供要观察的元素来订阅您正在创建的观察者。

observer.observe(this.elementRef.nativeElement);
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!