Jump to content
Search Community

Problem with animating/reseting width

jesper.landberg 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 done a super simple typewriter effect,  which works as intended, excerpt when u interrupt and restart it. The width of each char will just be correct until the previous reset point. Check the Pen to understand. If you let the whole timeline run before clicking the button, everything is fine, however, clicking it in the middle of the animation, messes up the next.

See the Pen 17da5944201f156706391328fe7421dd by ReGGae (@ReGGae) on CodePen

Link to comment
Share on other sites

please don't post private pens. we can't fork them.

 

is there a reason you don't just restart() the timeline?

Please try this code

const btn = document.querySelector('.js-play')
const split = new SplitText('.js-typewriter', { type: 'lines, words, chars' })

let tl = new TimelineLite({ paused: true })
  
  tl.staggerFrom(split.chars, 0.1, {
    width: 0,
    alpha: 0,
    ease: SteppedEase.config(1)
  }, 0.1)
  
function animate() {
  tl.restart();
}

btn.addEventListener('click', animate)

 

 

also, the TextPlugin basically does all that for you with even less code:

See the Pen GqKrxG?editors=0010 by GreenSock (@GreenSock) on CodePen

 

  • Like 2
Link to comment
Share on other sites

27 minutes ago, Carl said:

please don't post private pens. we can't fork them.

 

is there a reason you don't just restart() the timeline?

Please try this code


const btn = document.querySelector('.js-play')
const split = new SplitText('.js-typewriter', { type: 'lines, words, chars' })

let tl = new TimelineLite({ paused: true })
  
  tl.staggerFrom(split.chars, 0.1, {
    width: 0,
    alpha: 0,
    ease: SteppedEase.config(1)
  }, 0.1)
  
function animate() {
  tl.restart();
}

btn.addEventListener('click', animate)

 

 

also, the TextPlugin basically does all that for you with even less code:

See the Pen GqKrxG?editors=0010 by GreenSock (@GreenSock) on CodePen

 

 

Yeah, i can just restart unfortunaly.
Ohhh, I didn't even know about that plugin hah. Thanks.

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