- Revising GSAP scroll trigger again. All tutorials generally target DOM elements with
querySelector
, but GSAP works perfect with React refs.
- when installing on a react app/next.js. we need to remember to import
gsap
and ScrollTrigger
, then finally register the plugin. I think registration only needs to happen once, but it’s ok to register multiple times and it will treat it as a singleton.
import gsap from 'gsap';
import { ScrollTrigger } from 'gsap/dist/ScrollTrigger';
gsap.registerPlugin(ScrollTrigger);