<link rel="stylesheet" type="text/css" href="https://animate.style/animate-4.0.0.min.css">
Link: https://animate.style/
import inViewportAnim from '@pim.sk/utils/inViewportAnim.mjs
Adds CSS animation class (Animate.css) when element enters the viewport. Removes the class after the animation ends.
options = {
selector: ".inViewportAnim", // default CSS selector
anim: "fadeInLeft", // default Animate.css class
once: true, // default
}
fadeInLeftfadeInLeftfadeInLeft
new inViewportAnim({
selector: ".ivpa-basic-item",
anim: "fadeInLeft",
once: false,
})
Override animation settings per element with HTML attributes. data-anim overrides the default anim. data-delay and data-duration set CSS animation timing.
<div class="ivpa-item" data-anim="zoomIn">
<div class="ivpa-item" data-anim="fadeInDown" data-delay="300ms">
<div class="ivpa-item" data-anim="bounceIn" data-delay="600ms" data-duration="1.5s">
data-anim="zoomIn"data-anim="fadeInDown" data-delay="300ms"data-anim="bounceIn" data-delay="600ms" data-duration="1.5s"
// data-anim per element overrides the default anim option
new inViewportAnim({
selector: ".ivpa-attrs-item",
once: false,
})
Hook into the animation lifecycle. onViewport fires on viewport enter, then CSS animation events follow.
{
onViewport: (el) => {}, // element entered viewport
onAnimationStart: (el) => {}, // CSS animationstart
onAnimationEnd: (el) => {}, // CSS animationend
onAnimationCancel: (el) => {}, // CSS animationcancel
}
Animate me
new inViewportAnim({
selector: ".ivpa-cb-item",
anim: "fadeInLeft",
once: true,
onViewport: el => output.textContent += "→ onViewport\n",
onAnimationStart: el => output.textContent += "→ onAnimationStart\n",
onAnimationEnd: el => output.textContent += "→ onAnimationEnd\n",
})