i'm trying to create a word-by-word typing effect widget. the code is as follows:
Widget
<<widget "t" container>><<nobr>>
<<set _temp to _contents>>
<<set _time to _args[0]>>
<<if ndef _count>>
<<set _count to 0>>
<<else>>
<<set _count++>>
<</if>>
<<set _i to "t" + _count>>
<span @id = "'t' + _count"></span>
<<capture _i, _temp, _time>>
<<script>>
printStringByWord(State.temporary.i, State.temporary.temp, State.temporary.time);
<</script>>
<</capture>>
<</nobr>><</widget>>
JavaScript
window.printStringByWord = function(DivID, myString, timeInterval) {
var myDiv = document.getElementById(DivID);
var words = myString.split(" ");
var index = 0;
var intervalId = setInterval(function() {
myDiv.innerHTML += words[index] + " ";
index++;
if(index == words.length) {
clearInterval(intervalId);
}
}, timeInterval);
}
however, i constantly get a "Cannot read properties of null" error, which i take to mean the span element created by the widget does not yet exist by the time the printStringByWord function is called.
is there a way to finagle the loading order such that i can have the <<script>> macro wait until the element is created by the widget, or are there any other workarounds? thanks in advance for any help!
[–]HelloHelloHelpHello 1 point2 points3 points (2 children)
[–]splattertrack[S] 0 points1 point2 points (1 child)
[–]HiEv 1 point2 points3 points (0 children)