Jump to content
Search Community

Splittext on window resize

edonbajrami test
Moderator Tag

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

Hi, I have a text inside a div and then I'm calling SplitText function to seperate them into lines. But on window resize lines remais too long for mobile and I need them to recalculate on window resize to fit into browser witdth. How can I update on window resize lines that are created from SplitText ?

Link to comment
Share on other sites

I haven't use SplitText before so my suggestion is based on the 8 min video from the site..so don't judge me if I am wrong.. :)

 

From what I understand what you need is to call the SplitText whenever a resize event fires.

 

Take a look at this pen:

See the Pen bedqvz?editors=1111 by RedGlove (@RedGlove) on CodePen

 

Remember to turn on the console in codepen to see the outputs and start resizing. 

 

P.S.: I am not sure why, but the array created from SplitText includes an empty div at index=0. So if there are 5 actual lines, lines.length will be 6.

  • Like 3
Link to comment
Share on other sites

(please correct if I am wrong!!!)

 

Indeed it does but it doesn't change the line count because as you said its just CSS. In fact if you remove all the javascript and the CSS rule that you added from the pen you will get the same effect. I assumed that the line count may be needed for some kind of animation or something and if so, I guess the text needs to be separated and recalculated at every resize event. Then again if the line count is not needed and no animation is involved as you said the whole thing can probably be achieved by some "responsive" CSS. Aaahh speculations. :)

 

You said it right Jonathan: "Can you please provide a codepen demo so we can see your code live and in context to better help you?"

Link to comment
Share on other sites

The extra line was related to a line break in the HTML itself, but that has been resolved in the latest version of SplitText. You were just linking to an outdated one, that's all. I'd recommend always pointing to https://s3-us-west-2.amazonaws.com/s.cdpn.io/16327/SplitText.min.js in your codepens (note: that'll only work on the codepen domain). 

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