Jump to content
Search Community

SplitText not animating with scrolltrigger

Akash Ranjan test
Moderator Tag

Go to solution Solved by Cassie,

Recommended Posts


Heya!

You're nesting ScrollTriggers - easily done, it's one of the most common ScrollTrigger mistakes.

 

// you can add to a timeline
var words1 = gsap.timeline({
  scrollTrigger: {
    trigger: ".main-animation-div",
    markers: true,
    start: "100px 30%",
    end: "250px 25%"
  }
});

words1.fromTo(
  weakRouterWordsOne,
  {
    autoAlpha: 0,
    y: 90
  },
  {
    duration: 0.5,
    autoAlpha: 1,
    y: 0,
    ease: "power2.out",
    stagger: 0.1
  }
);
words1.fromTo(
  weakRouterWordsOne,
  {
    opacity: 1,
    y: 0
  },
  {
    duration: 0.5,
    opacity: 0,
    y: -90,
    ease: "power2.out",
    stagger: 0.1
  }
);

// or to a tween
gsap.to(weakRouterWordsThree,{
  autoAlpha: 0,
  y: 90,
  scrollTrigger: {
   trigger: ".main-animation-div",
   markers: true,
   start: "100px 30%",
   end: "250px 25%"
  }
});

// but not tweens inside timelines

weakRouterTl.fromTo(
        weakRouterWordsOne,
        {
          autoAlpha: 0,
          y: 90,
        },
        {
          duration: 0.5,
          autoAlpha: 1,
          y: 0,
          ease: 'power2.out',
          stagger: 0.1,
          scrollTrigger: {
            trigger: '.main-animation-div',
            // markers: true,
            start: '100px 30%',
            end: '250px 25%',
          },
        }
       
      )
      .fromTo(
        weakRouterWordsOne,
        {
          opacity: 1,
          y: 0,
        },
        {
          duration: 0.5,
          opacity: 0,
          y: -90,
          ease: 'power2.out',
          stagger: 0.1,
          scrollTrigger: {
           trigger: '.main-animation-div',
            // markers: true,
            start: '15% 30%',
            end: '18% 25%',
          },
        }
      )

 

  • Like 1
Link to comment
Share on other sites

Hi @Cassie,

 

Thanks alot for pointing out the issue. I have update all of them to a fromTo tween and added toggle actions so that they play again when entering back. Do you have any suggestions how I can improve this?

gsap.fromTo(
      weakRouterWordsTwo,
      {
        autoAlpha: 0,
        y: 90,
      },
      {
        duration: 0.5,
        autoAlpha: 1,
        y: 0,
        ease: 'power2.out',
        stagger: 0.1,
        scrollTrigger: {
          trigger: weakRouterSection.current,
          // markers: true,
          start: '18% 30%',
          end: '25% 25%',
          toggleActions: 'play none reverse none',
        },
      }
    )
    gsap.fromTo(
      weakRouterWordsTwo,
      {
        opacity: 1,
        y: 0,
      },
      {
        duration: 0.5,
        opacity: 0,
        y: -90,
        ease: 'power2.out',
        stagger: 0.1,
        scrollTrigger: {
          trigger: weakRouterSection.current,
          // markers: true,
          start: '40% 30%',
          end: '45% 25%',
          toggleActions: 'play none reverse none',
        },
      }
    )

 

Link to comment
Share on other sites

Yes it is working but partially.  I have updated the same codepen. The issue is I am using 2 fromTo tween on same element. One for making it appear and another for making it disappear after a while.

 



But the problem is that the text is visible on first scroll which I don't want.

Link to comment
Share on other sites

  • Solution

Yep, so that's because you have two conflicting 'from' values. from tweens and ScrollTriggers are immediately rendered at their start position, so when you have one tween that's saying "start from 0 opacity" and another later one saying "start from 1 opacity" there's a conflict and the later one is going to win. 

You could do something like this with one 'from' tween and one 'to' tween and immediate render false on the second one. This is probably the best route if you're using toggleActions so that you can define individual durations and eases for the animations

See the Pen abRLKbY?editors=1010 by GreenSock (@GreenSock) on CodePen



If you're scrubbing, you could just go for a timeline though - 

See the Pen OJBxEyP?editors=1010 by GreenSock (@GreenSock) on CodePen

  • Like 3
  • Thanks 1
Link to comment
Share on other sites

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...