trigger-animations
Version:
A lightweight animation-on-scroll trigger utility built with **GSAP + ScrollTrigger**. Add animation attributes to your HTML elements and let the script handle the rest.
22 lines (21 loc) • 914 B
JavaScript
import gsap from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";
import common from "./common";
import commonScrollTrigger from "./commonScrollTrigger";
import flip from "./flip";
import slide from "./slide";
import zoom from "./zoom";
function triggerAnimations({ duration, ease }) {
gsap.registerPlugin(ScrollTrigger);
const elements = document.querySelectorAll("[data-trigger]");
elements.forEach(element => {
gsap.from(element, Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ duration: duration || 1, ease: ease || "back.inOut" }, common(element)), slide(element)), flip(element)), zoom(element)), { scrollTrigger: Object.assign({ trigger: element, refreshPriority: 1 }, commonScrollTrigger(element)) }));
});
ScrollTrigger.refresh();
}
class Trigger {
constructor(config) {
triggerAnimations(config);
}
}
export default Trigger;