我试图在滚动页面时更改我的部分的活动类。我正在使用 intersectionObserver,但感觉很受困。我需要从 activeId 获取 activeElement 但不知道如何执行此操作。
这是我的代码:
const options = {
threshold: 0.75
}
let observer = new IntersectionObserver(check, options);
function check(entries) {
entries.forEach(entry => {
const activeId = entry.target.id;
const activeElement =
if(entry.isIntersecting){
activeElement.classList.toggle("your-active-class");
};
});
};
sections.forEach(section => {
observer.observe(section);
});
桃花长相依
相关分类