css - Intersection Observer - 如何循环或重新启动动画?
问题描述
我使用 InterSectionObserver 在网站上启动动画。我在 DIV 中有几个 svg,在它们到达 Viewpport 后,我在其中添加了“动画”类。到目前为止一切都很好。
这是我的 JS:
if (IntersectionObserver) {
//When the element is visible on the viewport,
//add the animated class so it creates the animation.
let callback = function(entries) {
entries.forEach(entry => {
//if the element is visible, add the animated class
if (entry.isIntersecting) {
entry.target.classList.add('animated');
observer.unobserve(entry.target);
}
})
}
//Create the observer
let observer = new IntersectionObserver(callback, {
root: null,
rootMargin: "-100px",
threshold: 0
});
//Get and observe all the items with the item class
let items = document.querySelectorAll('.animate');
items.forEach((item) => {
observer.observe(item);
});
我需要在播放后重新启动动画,最好在循环之间有一点延迟。我怎样才能做到这一点?
这里工作的 CodePen:https ://codepen.io/w3work/pen/RwKYgyV
解决方案
推荐阅读
- javascript - 使用 JS 切换可用的输入/无线电
- perl - 在 perl 中实例化函数中的哈希效率低吗?
- c++ - 为什么函数“funct”没有被执行?
- node.js - 错误:在安装 CRA 应用程序的纱线时写入 EIO 错误
- node.js - 如何在我的代码(Node.js&Discord.js)中解决这个问题:“node:8036”?
- javascript - 动态添加 colspan 并删除下一个 td
- javascript - 使用 knex 和 mysql 在 where 中使用嵌套选择从 where 中选择
- python - 使用 matplolib 在股票图表上跳过周末
- r - 您如何将 rJava 标准捕获为 R 字符向量?
- html - Bootstrap 4 模态背景在移动设备上没有响应