Skip to content

Instantly share code, notes, and snippets.

@alecperkins
Forked from bnb/names.js
Last active August 29, 2015 14:06
Show Gist options
  • Save alecperkins/915a329972f79b2affa0 to your computer and use it in GitHub Desktop.
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.
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