Skip to content

Instantly share code, notes, and snippets.

Created September 1, 2017 14:30
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Fake typing animation with async/await
async function nextFrame() {
return new Promise((resolve) => {
async function randomDelay(min, max) {
const delay = Math.random() * (max - min) + min;
const startTime =
while ( - startTime < delay) {
await nextFrame()
async function simulateTyping({string, target, min = 10, max = 80}) {
for (const letter of string) {
target.insertAdjacentText("beforeend", letter)
await randomDelay(min, max)
Copy link

rik commented Sep 1, 2017

// Example

  string: "hello world",
  target: document.querySelector(".fake-input"),
}).then(() => console.log("done"))

Copy link

sgriffey commented Sep 1, 2017

@rik rookie q:
how would you get it to "erase" typing, then loop through an array of strings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment