Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lines are not being wrapped #35

Closed
Slgoetz opened this issue Feb 8, 2019 · 5 comments
Closed

Lines are not being wrapped #35

Slgoetz opened this issue Feb 8, 2019 · 5 comments

Comments

@Slgoetz
Copy link

Slgoetz commented Feb 8, 2019

From the sound of the documentation when you split by lines it should wrap each line in a dom element

const results = Splitting({ 
         target:target, 
	by:'lines'
});

If that is not the case, is it possible to do that?

@shshaw
Copy link
Owner

shshaw commented Feb 8, 2019

The documentation should likely be clarified a bit more :-)

The way it works now is by splitting the words ( equivalent to Splitting({ by: 'words' }) ), then adds a --line-index variable to each .word. This setup was to lessen the impact on the DOM when lines needed to be recalculated on resize. If you have DOM elements for each line, you have to shuffle the child elements around on resize versus just updating the style property.

This has come up before. I'm not directly opposed to having line wrappers, but it definitely ups the complexity and impacts performance each time it runs; though would help performance of certain animations (animating .line elements versus all the .word elements)

Certainly open to feedback.

@notoriousb1t
Copy link
Collaborator

I think if this is added it should be behind an option. I personally like the line indexing instead of adding dom nodes, but I definitely understand the desire to have it split everything in the dom for a one-time split in certain cases.

@FrankM1
Copy link

FrankM1 commented Apr 27, 2019

I'm looking to have lines wrapped as well. This is a pretty common use case when animating text.

@tleifj
Copy link

tleifj commented Jul 1, 2019

Has anyone come up with a way to implement this? Looking for a solution as well!

@ParallelUniv3rse
Copy link

ParallelUniv3rse commented Sep 10, 2019

+1

EDIT: For anyone needing this functionality I came up with a workaround for now:

      const res = splitText({
        target: this.dom.heroText,
        by: 'lines'
      });

      res.forEach((splitResult) => {
        const wrappedLines = splitResult.lines.map((wordsArr) => `
        <span class="line">
          ${wordsArr.map((word) => `${word.outerHTML}<span class="whitespace"> 
         </span>`).join('')}
        </span>`).join('');
        splitResult.el.innerHTML = wrappedLines;
      });

@Slgoetz Slgoetz closed this as completed Apr 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants