Jump to content
Search Community

Changing text animation

meervdnick test
Moderator Tag

Recommended Posts

Hi Guys,

 

I am struggling to find an answer for my question, so i decided to try my luck over here.  What is am trying to accomplish is the following. I would like to display a changing word  loop on the front page of my website.  So for example, you see the word "developer"  after a few sec "designer" etc, you get the picture.  I dont want to appear the words like that, but that that animate in like in this website's example https://revolvestudio.co/. I've tried to look at the Splittext plugin to create the animation but i just can't  figure it out. I would higly appreciate if there is someone who can help me accomplish this.

 

Thanks a million!!

Link to comment
Share on other sites

Hey meervdnick and welcome to the GreenSock forums!

 

This sort of effect is quite simple to make. Simply have a list of words inside of a container and make sure that container has overflow:hidden; Then animate the words in and out of that container. Here's a demo from another recent thread that does this basic behavior:

See the Pen RKPdEV by marklc44 (@marklc44) on CodePen

 

To stagger the letters, I recommend using GSAP's SplitText as you commented. Modifying the above demo to also use GSAP 3 and SplitText you could do something like this:

See the Pen VwYKXzO?editors=0010 by GreenSock (@GreenSock) on CodePen

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

5 minutes ago, meervdnick said:

Can I make the text animate out the same way as it animates in? Can i do that by adding a reverse to it?

It depends what you mean. By "the same way as it animates in" do you mean go down then the next one comes up afterwards? If yes, you could use a reverse, yes. But it'd probably be easier to change the structure a bit and do something like this instead:

See the Pen WNbGzyj?editors=0010 by GreenSock (@GreenSock) on CodePen

 

If I'm misunderstanding what you're wanting please let me know :) 

Link to comment
Share on other sites

  • 2 years later...

 

Hello @terroarr

 

When you remove the overflow: hidden on the container you can see the full setup and compare what is going on 'behind the scenes' to the code you see. In Zach's latest codepen the elements are naturally stacked on top of each other, so you will first want to somehow invert the order. You could do that by adding an initial gsap.set in the forEach function that loops over the elements, something like this:

 

vsOpts.slides.forEach(function(slide, i) {
  
  gsap.set(slide, { y: i * -2 * vsOpts.lineHeight })
  
  ...
  
})

 

Now you will have them stacked the other way towards the top, and since you want to tween the other way around (from top to bottom instead of from bottom to top) now all you'd need to do would be to invert the values for the y properties in the tweens from negative to positive and vice versa.

 

So...

 

// ...this...
y: i * -1 * vsOpts.lineHeight

// ...would have to be this...
y: i * 1 * vsOpts.lineHeight



// ...this...
y: 50

// ...would have to be this...
y: -50



// ...and this...
y: -50

// ...would have to be this...
y: 50

 

Give it a shot yourself and if you get stuck, post back with a minimal demo of what doesn't work for you, and we'll be happy to help some more.

 

  • Like 2
Link to comment
Share on other sites

Hi @akapowl,

Thanks for replying to me. Your solution worked! thank you.

 

Wondering if you can help me reset the timeline on screen resize? I need to use vw for the font size, so I'm trying to grab the new height of the text when the screen resizes and then pass that through the function, but it doesn't seem to be working. Any ideas?

 

See the Pen NWMBJRb by mattmcgilton (@mattmcgilton) on CodePen

 

I'm not sure how to add a codepen into a comment.. 

 

Link to comment
Share on other sites

There are a few problems: 

  1. You are recreating everything over and over again on resize. So you'll end up with a bunch of competing infinitely-repeating animations. You should always kill() or revert() the old one (revert() is new in 3.11). 
  2. You aren't accounting for the current progress. So let's say the current animation is halfway through when you resize and it creates a whole new one - since you're using regular from()/to() tweens, it uses the CURRENT value as the end/start. See the problem?  

Here's a fork showing a solution (assuming I understood your goal correctly): 

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

  • Like 2
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...