Jump to content
Search Community

TextPlugin and Format Preservation

IanTheSecond test
Moderator Tag

Go to solution Solved by GreenSock,

Recommended Posts

Hello,

 

I wanted to create a console log typing effect with the GSAP TextPlugin. I have a container that has preserved formatted text (spaces for indentations and line breaks without <br>) that I tried to animate with gsap.from() method and the text: {value: ""} property. However, when not manipulated by GSAP, the formatting is fine. But when I used the method mentioned above, all indentations and line breaks are not respected. 

Is there a way for GSAP to preserve such format? 

 

I have tried the below example to simulate a text typing effect (another version with a timeout/await between each iteration) but I lose easing functionality that I would really love to have, though the method preserved the formatting.

for (var i = 0; i < text.length; i++) {
    container.textContent += text[i]
}

 

Thank you for your considerations. 

 

Link to comment
Share on other sites

3 hours ago, Cassie said:

Hi Ian,

 

Would it be possible to put together a minimal demo so we can see how you're formatting the text?

It's difficult to know what's going on without a look at the animation.

Thanks!

Hello Cassie, 

 

Here are the demos that I made just now. 

 

Unformatted text:

See the Pen KKmrXKr by ianthesecond (@ianthesecond) on CodePen

 

The results that I'm looking for:

See the Pen WNjYZvg by ianthesecond (@ianthesecond) on CodePen

Link to comment
Share on other sites

2 hours ago, GreenSock said:

You could also use a regular expression to do all that wrapping of <span> elements for you, add a class, and even adjust the duration based on how many characters are in each line so that you get a much more consistent speed: 

 

 

 

👍

 

Thank you for the suggestion! 

 

It is actually something that I have tried to do: putting a <br> tag in place of a "\n". However, the actual rawText contains multi-level indentations (or spaces) that gets treated as a single space rather than many individual ones by the TextPlugin between each 'word'. As you can see from the demos all of above. 

 

Is there a way for TextPlugin to not join the spaces? 

 

Once more, thank you for your reply! :)

Link to comment
Share on other sites

  • Solution
On 8/9/2021 at 4:16 AM, IanTheSecond said:

Is there a way for TextPlugin to not join the spaces? 

 

Not currently, but I'm contemplating a "preserveSpaces: true" option for the next release. In the meantime, you could sorta trick it by swapping in a character that you'd never use in the text and then swap it out again in an onUpdate to get the spaces in there as &nbsp; like:

See the Pen LYyqGRg by GreenSock (@GreenSock) on CodePen

  • Like 3
Link to comment
Share on other sites

2 hours ago, GreenSock said:

Not currently, but I'm contemplating a "preserveSpaces: true" option for the next release. In the meantime, you could sorta trick it by swapping in a character that you'd never use in the text and then swap it out again in an onUpdate to get the spaces in there as &nbsp; like:

 

 

Thank you so much!! 

 

Your replies among others are appreciated! 10/10 customer service~ 

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