Am trying to make animated text using javascript without external modules,
here is what i have achieved now:
let i = 0;
function animateText(){
const textContainer = document.querySelector('#skills');
let txt = 'I am a web developer';
setTimeout(function(){
if(i == txt.length) return;
textContainer.textContent += txt[i];
i++;
requestAnimationFrame(animateText);
}, 100);
}
requestAnimationFrame(animateText);
#skills {
border-right: 4px solid cadetblue;
padding: .2rem;
font-size: 2rem;
}
<span id="skills"></span>
my code works fine but i would like to make it more dynamic, the requestAnimationFrame API does not accept a function with parameters, so the question is how can i make a dynamic version of my code since the text and the element can be changed i want something like this
requestAnimationFrame(animateText(el, txt));
but this does not work since the animation API take the timestamp as an argument, https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame
any ideas or suggestions??