On Eric Amodio's website and JS.ORG, there is a Javascript animation which makes text appear/disappear as if it is being typed.
I tried to replicate something similar but far more basic on JSFiddle.
In my experiment, the words Code review
appear typed, are hidden by toggle(200)
, and the words Code review
appears again.
My final result was a mess of <span>
tags and massive blocks of consequent setTimeout()
JS functions.
<p><span id="bar"> |</span></p>
p {
line-height: 10px;
}
setTimeout(function() {
$("#bar").before("<span class='typed-letter'>C</span>");
}, 100);
setTimeout(function() {
$("#bar").before("<span class='typed-letter'>o</span>");
}, 200);
setTimeout(function() {
$("#bar").before("<span class='typed-letter'>d</span>");
}, 300);
setTimeout(function() {
$("#bar").before("<span class='typed-letter'>e</span>");
}, 400);
setTimeout(function() {
$("#bar").before("<span class='typed-letter'> </span>");
}, 500);
setTimeout(function() {
$("#bar").before("<span class='typed-letter'>R</span>");
}, 600);
setTimeout(function() {
$("#bar").before("<span class='typed-letter'>e</span>");
}, 700);
setTimeout(function() {
$("#bar").before("<span class='typed-letter'>v</span>");
}, 800);
setTimeout(function() {
$("#bar").before("<span class='typed-letter'>i</span>");
}, 900);
setTimeout(function() {
$("#bar").before("<span class='typed-letter'>e</span>");
}, 1000);
setTimeout(function() {
$("#bar").before("<span class='typed-letter'>w</span>");
}, 1100);
/* HIDE .TYPED-ANIMATION */
setTimeout(function() {
$(".typed-letter").toggle(200);
}, 1300);
/* SECOND ITERATION */
setTimeout(function() {
$("#bar").before("<span class='typed-letter'>C</span>");
}, 1600);
setTimeout(function() {
$("#bar").before("<span class='typed-letter'>o</span>");
}, 1700);
setTimeout(function() {
$("#bar").before("<span class='typed-letter'>d</span>");
}, 1800);
setTimeout(function() {
$("#bar").before("<span class='typed-letter'>e</span>");
}, 1900);
setTimeout(function() {
$("#bar").before("<span class='typed-letter'> </span>");
}, 2000);
setTimeout(function() {
$("#bar").before("<span class='typed-letter'>R</span>");
}, 2100);
setTimeout(function() {
$("#bar").before("<span class='typed-letter'>e</span>");
}, 2200);
setTimeout(function() {
$("#bar").before("<span class='typed-letter'>v</span>");
}, 2300);
setTimeout(function() {
$("#bar").before("<span class='typed-letter'>i</span>");
}, 2400);
setTimeout(function() {
$("#bar").before("<span class='typed-letter'>e</span>");
}, 2500);
setTimeout(function() {
$("#bar").before("<span class='typed-letter'>w</span>");
}, 2600);
Fiddle
- How can I use functions, arrays and loops in my JS/jQuery instead of massive blocks of consequent
setTimeout
functions to simplify my code and make it more efficient? - How can I make it so that the text also disappears in a 'typed' way, instead of using
toggle(200)
to hide the text again?