Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

typing animation in js

// typing animation in js:
//copy the following code:
const sleep = (milliseconds) => {
  return new Promise(resolve => setTimeout(resolve, milliseconds))
}

const applyTypingAnimation = async (element, delay) => {
  const stringToWrite= element.innerText;
  element.innerHTML= "";
  let refill= "";
  const cursorHTML= "▮";
  for (character of stringToWrite) {
    refill+= character;
    await sleep(delay)
    element.innerHTML= refill+cursorHTML;
  }
}

// calling the function:
applyTipingAnimation(/*your element*/, /*your delay*/)
 
PREVIOUS NEXT
Tagged: #typing #animation #js
ADD COMMENT
Topic
Name
5+5 =