-
-
Save alecperkins/915a329972f79b2affa0 to your computer and use it in GitHub Desktop.
Cycle through the names using `Array::shift` and `Array::push`, with recursive `setTimeout` instead of a loop so it's non-blocking.
This file contains 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
var names = [ | |
"&!", | |
"bnb", | |
"bang", | |
"bitnb", | |
"bitandbang", | |
"Tierney Coren" | |
] | |
function typeName() { | |
// Get the first name in the list and push it to the end. | |
var name = names.shift(); | |
names.push(name); | |
// Run the typing effect. | |
$('.title') | |
.typetype( | |
"I am " + name + ".", | |
{ | |
e: 0.04, // error rate. (use e=0 for perfect typing) | |
t: 100, // interval between keypresses | |
}) | |
.backspace( | |
name.length + 1, | |
{ | |
t: 100 // interval between keypresses | |
}); | |
// Set a timeout for the next call that's delayed by | |
// how long the typing effect takes. | |
setTimeout(typeName, (name.length * 2 + 1) * 100); | |
} | |
// Initial call. | |
typeName(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment