Created
October 8, 2025 08:29
-
-
Save Crenshinibon/5688e4038e33c9646ac807e05e001bfb to your computer and use it in GitHub Desktop.
Write and delete text letter by letter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| 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