Javascript: Fading text? ahhh.....

Passions

Diamond Member
Feb 17, 2000
6,855
2
0
I would like some lyrics on my webpage to fade in, a couple of verses each, and then stay there. But I donno hwo to do this, all the scripts seem to just scroll line by line and do not stay afterword. Can someone help me out?

so it be like this

fade in verse
stay
fade in next verse
stay
fade in next verse
stay

etc...
 

lupin

Platinum Member
Oct 11, 1999
2,944
0
0
Using an applet maybe.

I'm not sure you can do that using javascript.

-edit-
If you can do it using javascript, that'll be cool.
Let me know then. :)
 

Engine

Senior member
Oct 11, 1999
519
0
0
You can do it with Javascript. What you do is have the text start out as the same color as your background, and write a script to gradually change it to another color.

I don't have time right now to give a code example right now, but I'm sure you can find a script somewhere that does this. Try doing a search on DHTML scripts, instead of just Javascript.
 

Engine

Senior member
Oct 11, 1999
519
0
0
Okay, here's how you do it (this example fades text in from a white background to black text)
Put this in the <head> section of your page

<script language=&quot;Javascript&quot;>
//First, define an array to hold all your colors

colors=new Array();
colors[0]=&quot;#FFFFFF&quot;;
colors[1]=&quot;#EEEEEE&quot;;
colors[2]=&quot;#CCCCCC&quot;;
colors[3]=&quot;#999999&quot;;
colors[4]=&quot;#666666&quot;;
colors[5]=&quot;#333333&quot;;
colors[6]=&quot;#000000&quot;;

//some utility variables
var colorIndex = 0;
var text = null;
var timerFade = null;
var browserName = navigator.appName;
var browserVersion = parseInt(navigator.appVersion.substring(0,1));

//this only works with IE 4 and up
var dhtml = ((browserName == &quot;Microsoft Internet Explorer&quot;) &amp;&amp; (browserVersion > 3));

if (dhtml){
text = document.all(&quot;lyrics1&quot;);
LyricsFadeIn();
timerFade = setInterval(&quot;LyricsFadeIn()&quot;, 75);
}

//functions gradually changes the color
function LyricsFadeIn(){
text.style.color = colors[colorIndex];
colorIndex++;
if (colorIndex > 6) clearInterval(timerFade);
}


</script>

Then, where you have your lyrics in the body:
<span id=&quot;lyrics1&quot;>
There once was a girl from Nantucket...
</span>


And that's it. Of course, that'll only fade one piece of text into the page. If you want to do multiple texts, you'll just have to modify a couple things.
 

Engine

Senior member
Oct 11, 1999
519
0
0
Doh.. I suppose I should have tested that before I posted it. You have to put the Javascript down at the bottom of your page, instead of up in the head. Otherwise, when it calls the LyricsFadeIn function you'll get an 'Object required' error, because the 'lyrics1' object doesn't exist yet. If you move it to the bottom, the 'lyrics1' object will have been created already, so the script will work.