(function (doc) {
// this party startet
textAnim();
function textAnim() {
var con = doc.querySelector(".animation");
if (con) {
// get the text
var str = con.innerHTML;
var arr = str.split(" ");
//delete the text from container
con.innerHTML = "";
// create individual elements and add them to the container
arr.forEach(function (el) {
if (el != "\n") {
var newHTMLel = doc.createElement("span");
newHTMLel.innerHTML = el;
newHTMLel.classList.add("animation__elem", "hidden");
con.appendChild(newHTMLel);
}
});
// get the individual elements back an show them piece by piece
var list = con.childNodes;
var timer = 0;
list.forEach(function (el) {
setTimeout(function () {
el.classList.remove("hidden");
}, (timer += 200));
});
}
}
/*---------------*\
* only for show *
\*---------------*/
var btn = doc.querySelector(".restart");
btn.addEventListener("click", function () {
doc.querySelector(".animation").innerHTML = "text comes here";
textAnim();
});
})(document);