Skip to content

Instantly share code, notes, and snippets.

@Crenshinibon
Created October 8, 2025 08:29
Show Gist options
  • Select an option

  • Save Crenshinibon/5688e4038e33c9646ac807e05e001bfb to your computer and use it in GitHub Desktop.

Select an option

Save Crenshinibon/5688e4038e33c9646ac807e05e001bfb to your computer and use it in GitHub Desktop.
Write and delete text letter by letter
/*
Nice little function to emulate, typing and deleting of text ... stolen from bun website
*/
const options = ["runtime", "package manager", "bundler", "test runner", "all-in-one toolkit"];
async function replaceTyper() {
const typer = document.getElementById("typer");
const current = typer.innerText;
const next = options[(options.indexOf(current) + 1) % options.length];
const CHAR_DELAY = 40;
const WORD_DELAY = 2300;
stopBlink();
while (typer.innerText.length > 0) {
typer.innerText = typer.innerText.slice(0, -1);
// wait
await new Promise( (resolve) => setTimeout(resolve, CHAR_DELAY));
}
// type in next
for (let i = 0; i < next.length; i++) {
typer.innerText += next[i];
await new Promise( (resolve) => setTimeout(resolve, CHAR_DELAY));
}
startBlink();
// wait
await new Promise( (resolve) => setTimeout(resolve, WORD_DELAY));
replaceTyper();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment