Jump to content
Search Community

Can't keep <br> tags in inner html while using SplitText

nicolaseielll test
Moderator Tag

Go to solution Solved by Rodrigo,

Recommended Posts

  • Solution

Hi,

 

The problem is that when you create the second split to give each line a new parent the line that was created as a result of the two <br> tags is set to an empty element with no height since it has no text in it.

 

Using this HTML seems to work as you expect:

const innerHtml = "Lorem ipsum dolor sit amet<br>&nbsp;<br>Lorem ipsum dolor sit amet";

Also I consider a good practice when using SplitText in Vue, to wait for the next tick in order to be sure that the DOM has been correctly updated and the v-html directive has been applied correctly. Is just my opinion on the subject so take it with a grain of salt, but I prefer to do this:

mounted() {
  this.$nextTick(() => {
    var p = document.querySelector(".p");
    var splitP = this.getSplitText(p);
    gsap.set(splitP.lines, { opacity: 0, yPercent: 150, rotate: "5deg" });

    gsap.to(splitP.lines, {
      opacity: 1,
      yPercent: 0,
      rotate: 0,
      duaration: 1,
      ease: "Power3.easeInOut",
    });
  });
},

Here you can see a live example:

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

 

Let us know how it works and if you have any other question.

 

Happy Tweening!

  • Like 1
Link to comment
Share on other sites

I was too quick to celebrate. I cannot get it to work in that nuxt project in codesandbox. I also tried to set the innerHtml via javascript and not via using v-html but it did not have any effect.

 

If you try, are you able to get it working in the demo I provided? I have the exact same setup in local project.

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