JavaScript
(function(win, doc, $) {
"use strict";
(function() {
var timeline = [
{
txt: "H",
ms: 200
},
{
txt: "HE",
ms: 200
},
{
txt: "HEL",
ms: 200,
},
{
txt: "HELLO",
ms: 200
},
{
txt: "HELLOW",
ms: 400
},
{
txt: "HELLO",
ms: 200
},
{
txt: "HELLO ",
ms: 200
},
{
txt: "HELLO W",
ms: 200
},
{
txt: "HELLO WO",
ms: 200
},
{
txt: "HELLO WOR",
ms: 200
},
{
txt: "HELLO WORL",
ms: 200
},
{
txt: "HELLO WORLD",
ms: 200
},
{
txt: "HELLO WORLD.",
ms: 1000
},
{
txt: "HELLO WORLD.",
ms: 5000,
line: {
color: "transparent"
}
},
{
txt: "HELLO WORLD",
ms: 100,
line: {
color: "transparent"
}
},
{
txt: "HELLO WORL",
ms: 100,
line: {
color: "transparent"
}
},
{
txt: "HELLO WOR",
ms: 100,
line: {
color: "transparent"
}
},
{
txt: "HELLO W",
ms: 100,
line: {
color: "transparent"
}
},
{
txt: "HELLO ",
ms: 100,
line: {
color: "transparent"
}
},
{
txt: "HELLO",
ms: 100,
line: {
color: "transparent"
}
},
{
txt: "HELL",
ms: 100,
line: {
color: "transparent"
}
},
{
txt: "HEL",
ms: 100,
line: {
color: "transparent"
}
},
{
txt: "HE",
ms: 100,
line: {
color: "transparent"
}
},
{
txt: "H",
ms: 100,
line: {
color: "transparent"
}
},
{
txt: "",
ms: 1000,
line: {
color: "transparent"
}
}
];
(function buildAnimate(timeline) {
var INIT_MS = 500,
index = 0,
length = timeline.length,
$txt = $(".txt-copy"),
$line = $(".txt-underline"),
$cursor = $(".txt-cursor");
setInterval(function() {
$cursor.toggleClass("on");
}, INIT_MS);
(function animate(ms) {
setTimeout(function() {
var ms = timeline[index].ms;
$txt.text(timeline[index].txt);
$line.css({
width: $txt.width(),
background: (timeline[index].line && timeline[index].line.color) || "#fff"
});
$cursor.css({
background: (timeline[index].cursor && timeline[index].cursor.color) || "#fff"
});
index = ++index % length;
animate(ms);
}, ms);
})(INIT_MS);
})(timeline);
})();
})(this, document, $);