Jump to content
Search Community

Why does the splitted node from SplitText includes extra whiteSpace Note only the node which is next <br> Tag.

Jim Tim test
Moderator Tag

Recommended Posts

hello guys i'm stuck with this bug.
i'll explain the scenario.

I'm trying to perform word by word animation.
image.thumb.png.2b1e3c43b3e3461e25a16a88482923ec.png

 

1. in the output I want that white space so I added white-space: pre-wrap property.
the output : with the space I expected.

image.png.da9fd6be6a88855744d34c143f71cc9d.png

 

2. but if alter the container using splitText it give some minor extra-space how to prevent. you can notice by the width difference.
image.png.1e6472d4839bd16a20c2ed2224c59fe8.png

 

3. if you uncomment the width you'll face overflow wrap issue due to that minor extra space.

image.png.9a771cdbdb608a718195fcd282a43619.png

See the Pen XWybLjZ by dajeme7838- (@dajeme7838-) on CodePen

Link to comment
Share on other sites

  • Jim Tim changed the title to Why does the splitted node from SplitText includes extra whiteSpace Note only the node which is next <br> Tag.

Hi,

 

This is because you are using a regular space. It's fixed when you use &nbsp; instead:

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

 

Also just in case is a good idea to wait for the fonts to be ready before creating your SplitText instances:

document.fonts.ready.then(function () {
  // Create SplitText instances
});

 

Hopefully this helps.

Happy Tweening!

Link to comment
Share on other sites

@Rodrigo this does fix the issue. but in your solution, you are using &nbsp; only in the space after <br> tag.

 in my useCase the text content is dynamic I can't know what the user entered.

 check out this code-pen output. 

See the Pen qBQOaGa by dajeme7838- (@dajeme7838-) on CodePen


  if I use &nbsp; in all the spaces the splittext is unable to split the text by words instead it splits by line
 

Link to comment
Share on other sites

  • 4 months later...

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