Jump to content


Split Text / input box

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

So, I was playing around with the splitText demo, and was wondering how or if I could animate individual letters as someone types them into an input box.


This is really a crappy codepen, but you should be able to see the direction i'm trying to go in.

See the Pen IBDrJ by ccelestine (@ccelestine) on CodePen

It's sort of working the way I want, but the whole word is animating.


Do you think this would be possible with a bit more work?





Link to comment
Share on other sites

Hi Cyril,


Interesting idea, but the typing velocity creates an overwrite issue.


Right out the blue I can think perhaps using the blur and focus events to animate the complete text like in chat apps, but as you type it is quite an appealing challenge.


Another possibility could be use a timer element that starts on the keyup event, and when that timer is completed animate the text inside the element. The timer should be a GSAP instance, so every time the keyup event triggers the overwrite manager kill the previous tween:

var timerObj = {a:0};

  TweenLite.fromTo(timerObj, .5, {a:0},{a:1, onComplete:completeFunction});

function completeFunction()
  //splitText animation here

Other chance would be to use a fromTo() instance on the characters using each char offsetLeft property as the destination, like that you would avoid the overwrite issue. Also add each new character in an array, so only new characters are animated and not the entire phrase; in this case you should map the backspace key to remove the last element in the array and disable the delete key (if someone deletes a letter in the middle of the sentence you should track the current cursor position and apply that to the array, then things get a little tricky) for simplicity.


As you can see this can go from a very simple approach to a very complicated-perfectionist one, being the last one the ideal thing, but it'll depend on how much time you can put into this.


Sorry I didn't post any codepen of my own, but you caught me with little free time right now, hopefully I'll set up something during the week.



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.