Mulitple displays can be put in the same page but only one can be run at a time.
There are 4 parts to creating a display
In the script
In the document body
NUM relates to the display number, so for the first display this would be 1 and for a second display this would be 2 etc.
The style rule #tempSpan references the word being faded in, this is where you can change the colour of the word while it is fading in.
For an additional effect include a font size of 25px.
You can aslo adjust the fade rate and speed by changing the values of variables
var opacStep=4
var opacSpeed=10
While I would suggest leaving the opacSpeed at 10 you could change opacStep to anything between 1, for maximum fade, and 100 for no fade.
<HTML>phrase1Str=new Array("One fine day in the middle of the night<br>","Two dead men got up for a fight<br>","Back to back they faced each other<br>","Drew their swords and shot each other.")
<HEAD> <TITLE>Phrase reader</TITLE> <script type="text/javascript"> // Coded by Jeff // www.huntingground.freeserve.co.uk var phrase1=new phraseReader('display1',1,1000) // displayID ,wordSpeed in milliseconds, lineSpeed in milliseconds
var phrase2=new phraseReader('display2',500,1000)
phrase2Str=new Array("Yesterday I am going to the pictures<br>","I sat at the front at the back<br>","A woman she gave me some chocolates<br>","I ate them and gave her them back.")
running=0
function phraseReader(num,wordSpeed,lineSpeed){
var opacStep=4 // user definable
var opacSpeed=10 // user definable
var count=0
var strCount=0
var opacValue=0
var fadeTimer=null
var wordTimer=null
var phraseTimer=null
this.startReader=function(num){
if(running==1){return}
running=1
document.getElementById("d"+num).innerHTML="<span class=\"stop\" onclick=\"phrase"+num
+".stopReader("+num+")\">Stop</span>"
if(document.getElementById("display"+num).innerHTML.length>window["phrase"+num+"Str"].length){
document.getElementById("display"+num).innerHTML=" "
}
this.nextWord(num)
}
this.nextWord=function(num){
tempArray=window["phrase"+num+"Str"][strCount].split(" ")
tempEl=document.createElement("span")
tempEl.setAttribute("id","tempSpan")
tempEl.innerHTML=tempArray[count]
document.getElementById("display"+num).appendChild(tempEl)
if("filters" in document.body&&"alpha" in document.body.filters){
document.getElementById("tempSpan").filters.alpha.Opacity=0
}
else{
document.getElementById("tempSpan").style.opacity=0
}
setTimeout("phrase"+num+".fade('"+num+"')",1)
}
this.fade=function(num){
if("filters" in document.body&&"alpha" in document.body.filters){
document.getElementById("tempSpan").filters.alpha.Opacity=opacValue
}
else{
document.getElementById("tempSpan").style.opacity=(opacValue/100)-0.01
}
opacValue+=opacStep
fadeTimer=setTimeout("phrase"+num+".fade('"+num+"')",opacSpeed)
if(opacValue>=100){
document.getElementById("display"+num).removeChild(tempEl)
document.getElementById("display"+num).innerHTML+=tempArray[count]+" "
clearTimeout(fadeTimer)
opacValue=0
if(running==1){
wordTimer = setTimeout("phrase"+num+".nextWord('"+num+"')",wordSpeed)
}
count++
if(count==tempArray.length){
clearTimeout(wordTimer)
count=0
strCount++
if(strCount<window["phrase"+num+"Str"].length){
phraseTimer=setTimeout("phrase"+num+".nextWord('"+num+"')",lineSpeed)
}
if(strCount==window["phrase"+num+"Str"].length){
running=0
strCount=0
document.getElementById("d"+num).innerHTML="<span class=\"replay\" onclick=\"phrase"+num
+".replayPhrase("+num+")\">Replay</span>"
}
}
}
}
this.stopReader = function(num){
if(running==0){return}
clearTimeout(wordTimer)
clearTimeout(phraseTimer)
running=0
document.getElementById("d"+num).innerHTML="<span class=\"restart\" onclick=\"phrase"+num
+".restartReader("+num+")\">Restart</span> || <span class=\"replay\" onclick=\"phrase"+num
+".replayPhrase("+num+")\">Replay</span>"
}
this.restartReader=function(num){
if(running==1){return}
running=1
document.getElementById("d"+num).innerHTML="<span class=\"stop\" onclick=\"phrase"+num
+".stopReader("+num+")\">Stop</span>"
this.nextWord(num)
}
this.replayPhrase=function(num){
if(running==1){return}
clearTimeout(wordTimer)
count=0
strCount=0
document.getElementById("display"+num).innerHTML=" "
timer = setTimeout("phrase"+num+".startReader('"+num+"')",wordSpeed)
}
}
</script>
<style>
#tempSpan{
position:absolute;
filter:alpha(opacity=0);
opacity:0.1;
color:teal;
/*
font-size:25px;
*/
}
html>body #tempSpan{
position:static;
}
#d1,#d2,#d3{
cursor:hand;
cursor:pointer;
font-weight:bold;
}
.stop{
color:#AA0000;
}
.restart{
color:00AA00;
}
.replay{
color:0000AA;
}
</style>
</HEAD>
<BODY>
<P>
<div id="d1"><span onclick="phrase1.startReader(1)">View Phrase 1</span></div><BR>
<div id="display1" style="height:100px"> </div>
<div id="d2"><span onclick="phrase2.startReader(2)">View Phrase 2</span></div><BR>
<div id="display2" style="height:100px"></div>
</BODY>
</HTML>