Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
R.J. LaCount

SplitText not breaking hyphenated words

Recommended Posts

Hello,

 

I'm encountering what I believe is a very similar issue to this thread, but I can't seem to get the applicable part of the solution to work in my context.

 

I have some large hero copy in a narrow container with a hyphenated word that SplitText is unable to break apart. From what I'm reading in the linked thread, this is happening because the one "word" cannot be split into multiple divs, so I need to swap in a non-breaking dash character in for the regular one, but I'm not having luck pulling that part out into my demo.

 

Attached a couple of screenshots in case the hyphenated word is not rendering at the same spot on your end in the Codepen example.

02-after-splittext.png

01-before-splittext.png

See the Pen dEEPwo by TheFunkyMonk (@TheFunkyMonk) on CodePen

Link to comment
Share on other sites

If I'm understanding your request adding "words' to your split text type seems to make hyphens break correctly.

 

const split = new SplitText(text, { type: 'lines','words' });

 

Link to comment
Share on other sites

3 minutes ago, Visual-Q said:

If I'm understanding your request adding "words' to your split text type seems to make hyphens break correctly.

 


const split = new SplitText(text, { type: 'lines','words' });

 

 

I think you're seeing it break correctly after that change because the object isn't formatted correctly (should be

{  type: 'lines, words' }

) which is causing a JavaScript error preventing SplitText from running at all.

Link to comment
Share on other sites

Yeah you're right, could never be that easy....?

  • Like 1
Link to comment
Share on other sites

Good idea. The text is coming in dynamically from the CMS, but I suppose I could write a little JavaScript to wrap any instances of hyphens in span elements before running SplitText.

Link to comment
Share on other sites

@Visual-Q Yep, simply adding the following:
 

text.innerHTML = text.innerHTML.replace("-", "<span>-</span>");

 

Prior to running SplitText does the trick. Appreciate the advice!

  • Like 1
Link to comment
Share on other sites

Great! Might be worth noting to the writer/editor to avoid hyphenation unless absolutely necessary, a lot of the time it's optional or at least a soft grammatical error that can be acceptable in problematic typesetting.

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