javascript - 交叉点观察者中有 entry.target.Classname 吗?
问题描述
我正在尝试通过交叉点观察器有条件地触发动画。我曾经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);
})
我想根据满足的类名条件触发类 .anim 的动画?有没有这样的方法?
我是一个完全的初学者顺便说一句。谢谢
解决方案
你可以试试这个:
if(entry.target.classList.contains('anim') && entry.intersectionRatio > 0)
推荐阅读
- c++ - 如何让多个整数传递多个函数?
- ios - 为什么在 iOS WKWebView 上不能下载一些图片
- c# - 如何在 where 条件下使用其他属性值更新 Azure 存储表一个特定属性值?
- mongodb - Mongoose 填充数组并返回所有文档(即使未找到填充)
- twitter-bootstrap - div在引导程序中使用而不是表
- python - 如何使用 python 和 Flask 在网页上显示和编辑文本文件?
- android - 显示警报 requestPermissions close Activity 时出现问题
- reactjs - React Hooks - 无效的 Hook 调用
- google-play - 我的应用处于生产状态,但是当我点击“在 Google Play 上查看”时,它显示错误
- vba - 使用子参数访问 VBA 更新表单文本框