api - Intersection Observer API addClass 不被观察
问题描述
使用 Intersection Observer API,是否可以classList.Add
用于不是“观察到”的特定 div?
我想做的是:当 div.upup
可见时, div.logoup
将获得额外的 class .logonew
。
这是我的代码,但不幸的是我不知道如何定位.logoup
div。
请帮忙 :)
entry.forEach((change) => {
if(change.isIntersecting) {
change.target.classList.add('logonew');
}
});
}
let options = {
threshold: [0.5]
};
let observer = new IntersectionObserver(onEntry, options);
let elements = document.querySelectorAll('.upup');
for (let elm of elements) {
observer.observe(elm);
}
解决方案
推荐阅读
- mysql - Is there is any way to push my database changes to github using git bash?
- javascript - 如何为以太坊智能合约制作图表
- ios - App Store Connect 操作错误,“尝试启动 iTMSTransporter 时发生错误”
- spring-boot - 将第 3 方 JAR 添加到用于远程服务器的 Spring Boot War Build
- autodesk-forge - 查看器 setThemingColor Promise
- opencart - 如何在多个域中共享打开的购物车会话
- java - JSON字符串验证多个类
- python - 将上限添加到日期时间(非固定频率)
- oracle - 在 ORACLE 中查询两个不同的数据库
- php - 如何在 Laravel 的数组中显示计算?