I have a <p> tag
<p id="rev">|</p>
that I want to continuously change via Javascript to create an old-school loading animation that would follow this pattern in repetition:
| / - \
I'm not familiar with how Javascript treats recursion, but the following block of code simply creates a long loading period and doesn't function as intended:
function runRev() {
document.getElementById('rev').innerHTML = "/";
setTimeout(function(){}, 2000);
document.getElementById('rev').innerHTML = "-";
setTimeout(function(){}, 2000);
document.getElementById('rev').innerHTML = "\\";
setTimeout(function(){}, 2000);
document.getElementById('rev').innerHTML = "|";
setTimeout(function(){}, 2000);
runRev();
}
runRev();
I imagine there is a better way to accomplish this. How can I create a Javascript function that continuously runs to change that single character?