Trigger animation with GSAP ScrollTrigger

I've created a CSS3 Animation with a scroll trigger that I'd need in GSAP ScrollTrigger since AddEventListener('scroll'... is not compatible with GSAP because it uses some different mechanisms for scrolling.

This is the current animation that I've created:

This is what I've tried to do in GSAP ScrollTrigger, but hasn't worked:

gsap.to('.glitch-slide', { keyframes: { "0%": { backgroundPosition: '0 0' }, "10%": { backgroundPosition: '5px 0' }, "20%": { backgroundPosition: '-5px 0' }, "30%": { backgroundPosition: '15px 0' }, "40%": { backgroundPosition: '-25x 0' }, "50%": { backgroundPosition: '-50px 0' }, "60%": { backgroundPosition: '0 -20px' }, "70%": { backgroundPosition: '-60px -20px' }, "80%": { backgroundPosition: '0 0' }, "90%": { backgroundPosition: '20px 0'}, "100%": { backgroundPosition: '0 0'}, easeEach: 'expo.inOut' }, ease: 'none', duration: 1
})

1 Answer

You can add your keyframes to css and create class that init this animation. With that all you need to start this animation is to add created class to element using ScrollTrigger.

onEnter

onEnter: ({progress, direction, isActive}) => documentQuerySelector('.my-selector').classList.add('active')

or

toggleClass: {targets: ".my-selector", className: "active"}

Here are examples

0

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like