Professional Documents
Culture Documents
Typing
Typing
addEventListener("DOMContentLoaded",()=>{
let yourName = prompt("What is your name"),
paragraph = document.getElementById("paragraph");
if(yourName != null){
paragraph.innerHTML = `Hello ${yourName}`;
paragraph.style.width = '0%';
typingAnimation();
} else {
alert("Please enter a name next time!");
}
function typingAnimation(){
let typingSpeed = 60, step = 0,
increment = 100 / paragraph.innerHTML.length, typing = true;
function type(){
if(typing){
step += increment;
paragraph.style.width = `${step}%`;
if(step >= 100){
paragraph.style.width = '100%';
typing = false;
clearInterval(interval);
gravity();
}
}
}