tameemsafi / typewriterjs

A simple yet powerful native javascript plugin for a cool typewriter effect.
https://www.npmjs.com/package/typewriter-effect
MIT License
2.46k stars 220 forks source link

Is there a way to skip the typewriting effect? So if someone wants to not wait just click a button SKIP #173

Open mastmaster opened 1 year ago

mdhgriffiths commented 1 year ago

I was able to get this working by running .stop() and using state.elements.wrapper.innerHTML to fill in the text - here's a snippet of what worked within my application (used currentTypewriter to store the typewriter and text strings):

  let currentTypewriter:{
    typewriter: TypewriterClass
    text: string
  }|null = null

  const stopTyping = () => {
    if (currentTypewriter) {
      const { typewriter, text } = currentTypewriter
      const { cursor, wrapper } = typewriter.state.elements
      cursor.setAttribute('hidden', 'hidden')
      wrapper.innerHTML = text
      typewriter.stop()
    }
  }