Jump to content
Search Community

Looping text with variable length

mackao test
Moderator Tag

Go to solution Solved by elegantseagulls,

Recommended Posts

Hi,

I'm a beginner for both js and gsap, but I have a idea about what I want to have

I what to have a text rolling in the bottom of my site, and I found this answer from Mikel:

This work perfect when the texts are about the same size

The problem is that my is'nt

I've found a lot of solutions for the loop, but all uses either a fixed width, or the width of the first element

 

As you can see on my codepen, the text is removed to soon, when leaving on the left side

Is this possible to fix?

See the Pen xxRbMgW by mackao (@mackao) on CodePen

Link to comment
Share on other sites

Hey mackao and welcome to the GreenSock forums.

 

The issue is logical: How can you get the width of all of your texts? Since they differ you can't just get the width of one and multiply it by how many there are.

 

There are two main approaches to getting the width:

  1. Positioning each of your elements in the same row (like display: inline-block with no wrapping or something similar), making sure the parent container has the full width of all of the children (i.e. is not restricted by the viewport's size). Then get the size of the container.
  2. Iterate through each of your elements, adding their width (and any spacing between them) together. Then after your iteration is done, you have the full width.

Once you have the full width, you will need to adjust the wrapping logic to use that number instead.

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