Jump to content
GreenSock

pakl

SplitText: <br> tags and spaces

Go to solution Solved by GreenSock,

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

I'm working on applying styling to certain words after using SplitText. To do this I'm relying on the word index but I see some inconsistencies when a linebreak is considered a word and when it isn't.

 

The following pen illustrates:

 

 

As you can see when a linebreak is followed or preceded by a space it will end up as a separate line and word after SplitText but if two or more linebreaks are not separated by anything else, they are combined into one line/word.

 

I think it's fair to consider this a bug. A linebreak should always end up as its own line with its own word, or am I missing something?

See the Pen goGuA by patrickklug (@patrickklug) on CodePen

Link to comment
Share on other sites

Great catch! Sorry about that. I just uploaded a new version in the bonus zip - please try that (version 0.3.1) and let me know if it resolves things for you. 

  • Like 2
Link to comment
Share on other sites

Hi pakl  :)

 

if two or more linebreaks are not separated by anything else, they are combined into one line/word."

 

i can't see the issue that you mentioned , the <br> tags split correctly :

 

See the Pen qwfLK by MAW (@MAW) on CodePen

 

 

edit : ooops ... so i`m playing with new js :) , thanks JACK 

Link to comment
Share on other sites

@Jack what is the best way to link to the latest version in a codepen?

 

I tried the new version locally and it seems that there is a breaking bug.

 

Using splittext on 'This is a test<br><br>Normal italic bold underline' returns a `.words` array with only 3 elements.

Link to comment
Share on other sites

Sorry about that - I uploaded the wrong file. Let me get back to you later today with the new/correct one. Please stand by...

Link to comment
Share on other sites

  • Solution

Please snag 0.3.2 now and give that a shot - it should fix all the <br> issues and the faulty words array that was introduced in that [wrong] file yesterday. Again, I apologize for the mix-up. Please let me know if things work well for you now. Oh, and if you want to use it on codepen, this URL should work: https://s3-us-west-2.amazonaws.com/s.cdpn.io/16327/SplitText.min.js

  • Like 3
Link to comment
Share on other sites

Thanks Jack, I'll give it a whirl.

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