So I was making a simple text animation and decided to make it so once its done, you can restart it. Problem being, im not sure of a way to force it to restart onclick once done. The way im doing it, it can and will restart in the middle if you click the screen, which is fine, but it continues to print some text from before. Anyway heres my code
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1 id=typing-style></h1>
<script>
var i=0,text="Mitchell";
setInterval(()=>{
document.getElementById("typing-style").innerHTML += text.charAt(i);
i++;
},300)
function rerun() {
document.getElementById("typing-style").innerHTML = " ";
var i=0,text="Mitchell";
setInterval(()=>{
document.getElementById("typing-style").innerHTML += text.charAt(i);
i++;
},300)
}
</script>
<canvas id="screen" onclick="rerun()" width=1000% height=1000%></canvas>
</body>
</html>
So what I've been trying to do is get it to be able to restart when you click the screen, but stop the current process. Hope someone can figure it out.