velgor
08-06-2008, 06:09 PM
Hi folks, I need some help with a DHTML ticker I'm working with. Currently the script outputs (via innerHTML) a message from a single variable--I need to adapt this to cycle through multiple messages from an array. Any help would be GREATLY appreciated. Here's the script:
var outputDiv = null;
var typedPortion = '';
var cursorChar = '';
var cursorHTML = '<span class="cursorChar">@<\/span>';
var workHTML = '';
var count = 0;
var typing = setInterval('typeText();', 20);
var message = 'A typed message with <span class=\"foo\" style=\"color: #990000\">embedded<\/span> html.';
var msgLength = message.length;
function typeText() {
outputDiv = document.getElementById('outputDiv');
if (count == msgLength) {
clearInterval(typing);
return;
}
else if (count == 0) {
typedPortion = '';
}
else {
typedPortion = message.substring(0, count);
cursorChar = message.charAt(count);
}
if (/</.test(cursorChar)) {
var tag = message.substring(count).match(/<\/?[^>]+>/);
if (tag) {
typedPortion += tag[0];
count += tag[0].length;
}
}
else {
workHTML = '';
workHTML += typedPortion;
if (count != msgLength - 1) {
workHTML += cursorHTML.replace(/@/, cursorChar);
outputDiv.innerHTML = workHTML;
count++;
}
}
}
window.onload = function() {
typeText();
}
Thanks a bunch!
var outputDiv = null;
var typedPortion = '';
var cursorChar = '';
var cursorHTML = '<span class="cursorChar">@<\/span>';
var workHTML = '';
var count = 0;
var typing = setInterval('typeText();', 20);
var message = 'A typed message with <span class=\"foo\" style=\"color: #990000\">embedded<\/span> html.';
var msgLength = message.length;
function typeText() {
outputDiv = document.getElementById('outputDiv');
if (count == msgLength) {
clearInterval(typing);
return;
}
else if (count == 0) {
typedPortion = '';
}
else {
typedPortion = message.substring(0, count);
cursorChar = message.charAt(count);
}
if (/</.test(cursorChar)) {
var tag = message.substring(count).match(/<\/?[^>]+>/);
if (tag) {
typedPortion += tag[0];
count += tag[0].length;
}
}
else {
workHTML = '';
workHTML += typedPortion;
if (count != msgLength - 1) {
workHTML += cursorHTML.replace(/@/, cursorChar);
outputDiv.innerHTML = workHTML;
count++;
}
}
}
window.onload = function() {
typeText();
}
Thanks a bunch!