I have an array of words and I would like to change a div tag to each word in sequence with a delay.
<script>
function printWord(w) {
setTimeout(function() {
$("#word").text(w);
}, 1000);
}
function readBook() {
var array = $("#offscreen_text").text().toString().split(/[\s\n]+/);
for (i =1; i < array.length; i++){
printWord(array[i]);
}
}
</script>
<body onload="readBook()">
<div id="word"></div>
<div id="offscreen_text">hi hello bye goodbye this is a test with some random text</div>
</body>
When I run readBook() nothing seems to be happening.
Aucun commentaire:
Enregistrer un commentaire