Javascript 交叉点观察者中是否有entry.target.Classname?
我试图通过交叉点观察者有条件地触发动画。我使用Javascript 交叉点观察者中是否有entry.target.Classname?,javascript,frontend,intersection-observer,Javascript,Frontend,Intersection Observer,我试图通过交叉点观察者有条件地触发动画。我使用document.queryselector.all调用某个类的项,然后使用另一个document.queryselector.all调用另一个类的项 我有两个不同的动画是通过交叉点观察者触发的,但是我希望它们是根据它们的类名有条件地触发的。有办法做到这一点吗 const Images = document.querySelectorAll ('.anim',); const lines = document.querySelectorAll (
document.queryselector.all
调用某个类的项,然后使用另一个document.queryselector.all
调用另一个类的项
我有两个不同的动画是通过交叉点观察者触发的,但是我希望它们是根据它们的类名有条件地触发的。有办法做到这一点吗
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);
})
我想触发类的动画。动画基于类名条件是否满足?有这样的方法吗
顺便说一句,我是一个完全的初学者。
谢谢你,你可以试试这个:
if(entry.target.classList.contains('anim') && entry.intersectionRatio > 0)