Skip to content

Instantly share code, notes, and snippets.

@timble-one
Created June 3, 2025 15:05
Show Gist options
  • Select an option

  • Save timble-one/40e1fbaa2cb36254d4831d5367a40449 to your computer and use it in GitHub Desktop.

Select an option

Save timble-one/40e1fbaa2cb36254d4831d5367a40449 to your computer and use it in GitHub Desktop.
const typewriter = document.getElementById('typewriter');
let index = 0;
function type() {
if (index < text.length) {
typewriter.innerHTML = text.slice(0, index) + '<span class="blinking-cursor">|</span>';
index++;
if (['!', '.', '\n'].includes(text[index-2])) {
setTimeout(type, Math.random() * 1500);
} else if (index % 10 == 0 && text[index-2] == ' ') {
setTimeout(type, Math.random() * 600);
} else {
setTimeout(type, Math.random() * 100);
}
} else {
typewriter.innerHTML = text.slice(0, index) + '<span class="blinking-cursor">|</span>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment