typewriterjs icon indicating copy to clipboard operation
typewriterjs copied to clipboard

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

Open mastmaster opened this issue 2 years ago • 1 comments

mastmaster avatar Feb 09 '23 06:02 mastmaster

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()
    }
  }

mdhgriffiths avatar Feb 14 '23 19:02 mdhgriffiths