【发布时间】:2021-06-16 22:12:14
【问题描述】:
我正在关注有关 IntersectionObserver 的教程,但我似乎无法让它工作......我正在尝试对视口中可见的元素应用动画。我将在此处粘贴 JS 代码,此处包含 html 和 css 的完整示例:https://codepen.io/cucurutcho/pen/KKWRrov
const images = document.querySelectorAll('.anim');
console.log("I'm working!");
observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
console.log("I'm working 2!");
if(entry.intersectionRatio > 0) {
entry.target.style.animation = `fadeInUp animated animatedFadeInUp`;
}
else {
entry.target.style.animation = 'none';
}
})
})
images.forEach(image => {
console.log("I'm working 3!")
observer.observe(image)
})
非常感谢任何帮助!非常感谢大家
【问题讨论】:
标签: javascript html css intersection-observer