Reputation: 83
How would I use HTML/Javascript to make text change, looping through a predetermined sequence?
Kind of like this, but in text form, instead of GIF
Thanks!
Upvotes: 1
Views: 14407
Reputation:
<script>
var example = ['A', 'B', 'C', 'D'];
textSequence(0);
function textSequence(i) {
if (example.length > i) {
setTimeout(function() {
document.getElementById("sequence").innerHTML = example[i];
textSequence(++i);
}, 1000); // 1 second (in milliseconds)
} else if (example.length == i) { // Loop
textSequence(0);
}
}
</script>
And the div to show the sequence:
<div id="sequence"></div>
Upvotes: 8