Jump to content
Search Community

Using ScrollTrigger to fire an anime animation when in view

Phil Owen

Recommended Posts

Posted

Hi, pretty new to GSAP and Scrolltrigger but really want to get familiar with it and use it going forward.

I'm trying to get spltjs text animating in on scroll with Scrolltrigger (Yes I know SplitText plugin exists but testing out external library functions with ST) but not having much luck.

Codepen:


 

See the Pen RwXKQvB by powen-cs (@powen-cs) on CodePen.

Posted

Hi Sahil

Ah, I get it, so setting the
 

for(var i = 0; i < heroText.length; i++){
  var target = heroText[i];


and then setting the target in ST then runs through each iteration from the above.  Thanks so much for your help!

  • Like 1
  • 11 months later...
Anime Witcher
Posted

You can definitely use GSAP’s ScrollTrigger to fire an anime.js animation when the element comes into view. The key is to hook into ScrollTrigger’s callbacks (onEnter, onLeave, etc.) and then trigger your anime.js timeline or animation inside them.

 

gsap.registerPlugin(ScrollTrigger);

ScrollTrigger.create({
  trigger: ".my-element",
  start: "top 80%", // adjust where you want it to fire
  onEnter: () => {
    anime({
      targets: ".my-element",
      translateY: [100, 0],
      opacity: [0, 1],
      easing: "easeOutExpo",
      duration: 1000
    });
  }
});
 

 

This way ScrollTrigger controls when the animation starts, and anime.js handles how it animates.
If you need the animation to replay when scrolling back up, you can also use onEnterBack.

Posted

@Anime Witcher just curious why you'd use anime for the animation if you're already loading GSAP anyway (and GSAP can do pretty much anything anime can do plus more). It's totally fine, of course, if someone wants to also load anime and use it with ScrollTrigger. I'm just curious about the reasoning. 

  • Like 2

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...