[英]is there an entry.target.Classname in intersection observer?
I am trying to conditionally trigger animations via intersection observer.我正在尝试通过交叉点观察器有条件地触发动画。 I have used
document.queryselector.all
to call items of a certain class, and then another document.queryselector.all
to call items of a different class.我使用
document.queryselector.all
调用某个 class 的项目,然后使用另一个document.queryselector.all
调用不同 class 的项目。
I have two different animations being triggered via intersection observer, but I want them to be triggered conditionally based on their classname.我有两个不同的动画通过交叉点观察器触发,但我希望它们根据它们的类名有条件地触发。 is there a way to do this?
有没有办法做到这一点?
const Images = document.querySelectorAll ('.anim',);
const lines = document.querySelectorAll ('.lines');
let callback = (entries, observer)=> {
entries.forEach(entry => {
if(entry.target.className === '.anim' && entry.intersectionRatio > 0){
console.log (entries);
entry.target.style.animation = `pcb_grp_anim 1s ${entry.target.dataset.delay} forwards ease-in-out`
}
else {
entry.target.style.animation = 'none';
}
})
}
let observer = new IntersectionObserver (callback);
Images.forEach (image => {
observer.observe(image);
})
I want to trigger the animation for class.anim based on class name condition being met?我想根据 class 名称条件为 class.anim 触发 animation? Is there such a way?
有没有这样的方法?
I am a total beginner BTW.顺便说一句,我是一个完全的初学者。 Thanks
谢谢
You could try this instead:你可以试试这个:
if(entry.target.classList.contains('anim') && entry.intersectionRatio > 0)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.