...

View Full Version : Need help with DHTML typewriter ticker



velgor
08-06-2008, 07: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!

ninnypants
08-06-2008, 07:26 PM
This section right here is a working example of what you want you'll be able to mod it to do what you want


var cnt=1;
var stories = new Array('story1','story2','story3','story4','story5');
function initializeTimer(id) {
document.getElementById(id[cnt]).style.display=block;
timerID = setInterval('chgImage(stories)', 5000) // change the image every 5 seconds
}
function chgStory(id) {
document.getElementById(id[cnt]).style.display='none';
cnt=++cnt%stories.length; // this just cycles 0,1,2,3,4,5,0,1,2..
document.getElementById(id[cnt]).style.display='block';
}
initializeTimer(stories);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum