Jump to content
Search Community

Target a specific character from a string.

Lrd0sh test
Moderator Tag

Go to solution Solved by akapowl,

Recommended Posts

Hello, I'd like to know if there's a way in Gsap or splitText  to target a specific character from a word so that I can apply some effects on it, say I wan to tilt only the letter "L" from the word "help". I've looked into it and the closest I could find to a solution is based on jQuery, and I'd like to keep it Gsap all the way if possible. 

Link to comment
Share on other sites

  • Solution

 

Hey @Lrd0sh

 

If what you want is as simple as only just adressing one character and it doesn't have to follow any specific logic, it is pretty uncomplicated.

 

Since whatever you split your text by (which in your case with the word help probably is chars) will return an array of all the wrapping divs that are being created, you can address the element you want by using its index

 

See the Pen 4418c18ec371ac020134eaf4286967d3 by akapowl (@akapowl) on CodePen

 

 

If you'd want it to specifically be the letter "l" in every case though, I think you'd have to incorporate some logic for that.

Something like this could work

 

See the Pen b502b67243598ae2d8b14b06ca3af157 by akapowl (@akapowl) on CodePen

 

 

 

  • Like 4
Link to comment
Share on other sites

1 hour ago, Lrd0sh said:

I made it work with a bunch of <spans>, but my understanding is that it's not good for SEO

It's probably not a big deal for SEO but algorithms for that differ and change all the time so I can't say for sure. If you do it with JS once the page loads it should be perfectly fine though.

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