You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
585 B
JavaScript

const tekst = document.getElementById("stiligtekst");
const tekstStr = tekst.textContent;
const splitta = tekstStr.split("");
tekst.textContent ="";
for (let i =0; i < splitta.length; i++) {
tekst.innerHTML +="<span>" + splitta[i] + "</span>";
}
let char = 0;
let timer = setInterval(onTick, 100);
function onTick(){
const span = tekst.querySelectorAll('span')[char];
span.classList.add('stilig');
char++;
if(char === splitta.length) {
complete();
return;
}
function complete(){
clearInterval(timer);
timer = null;
}
}