[thelist] Javascript: randomizing persistent text rotator

Timothy Martens timfm at hawaii.rr.com
Sun Mar 24 20:02:01 CST 2002


Can someone help me to randomize the display of the Array below? I know
it something like: var randy = Math.floor(Math.random()*txtStr.length),
but I can't get it to work smoothly. As always -- comments about
improving code structure/logic are welcome.


var Speed = 500;
var txtStr = new Array("1","2","3","4","5","6","7");

if (document.layers) {
document.write('<ilayer id="NN4"><layer id="NN42" height=25
width=100%><\/layer><\/ilayer>')
temp =
'document.NN4.document.NN42.document.write(txtStr[i++]);'+'document.NN4.
document.NN42.document.close()';
}
else if (document.getElementById) {
document.write('<div id="message"
style="position:relative;">...<\/div>');
temp = 'document.getElementById("message").firstChild.nodeValue =
txtStr[i++];';
}
else if (document.all) {
document.write('<div id="message"
style="position:relative;">...<\/div>');
temp = 'message.innerHTML = txtStr[i++];';
}

var i = 0;
function rotateR() {
eval(temp);
if (i == txtStr.length) i = 0;
setTimeout("rotateR()", Speed);
}
window.onload = rotateR;


Thanks!	//t




More information about the thelist mailing list