【发布时间】:2020-10-20 05:04:48
【问题描述】:
我已经在我的主页上设置了 Intersection Observer API。我有从导航菜单链接到 id 的部分。每个部分在单击时从页面滚动到时都会成功触发 Intersection Observer 回调。
我从导航菜单中的其他页面链接到这些相同的部分,但是当单击其中一个链接时,会导航到主页上的部分,但不会执行 Intersection Observer 回调。
以下是导航链接的示例:index.html#about-us
路口观察员代码:
var aboutUs = document.querySelector('#about-us');
var observer = new IntersectionObserver(function(entries) {
if(entries[0].isIntersecting === true) {
entries[0].target.style.opacity = '1';
}
}, { threshold: [0.5] });
observer.observe(aboutUs);
如果有人有这方面的经验,请告诉我。
【问题讨论】: