Add the class scroll-highlight
to your text element
<script src="https://cdn.jsdelivr.net/npm/gsap@3.12.5/dist/gsap.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/gsap@3.12.5/dist/ScrollTrigger.min.js"></script>
<script src="https://unpkg.com/split-type"></script>
<script>
gsap.registerPlugin(ScrollTrigger);
const splitTypes = document.querySelectorAll('.scroll-highlight');
splitTypes.forEach((char,i) => {
const text = new SplitType(char, {types: ['chars','words']});
gsap.from(text.chars, {
scrollTrigger: {
trigger: char,
start: 'top 80%',
end: 'top 20%',
scrub: true,
},
opacity: 0.2,
stagger: 0.1,
})
});
</script>