Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fade text in ????? help!

Status
Not open for further replies.

DOGWATCH

Programmer
Mar 11, 2004
120
0
0
US
I would like to make a nice little text effect on my site where the text slowly fades in from white to black.

I found this code below but it just seems to do nothing. Also I would prefer not to use a java applet but rather Javascript or DHTML. Again the text should just fade in once and stop
going from white to black.

any ideas??

Code:
<script type="text/javascript">
hex=255 // Initial color value.
function onPageLoad(){ 
if(hex>0) { //If color is not black yet
hex-=11; // increase color darkness
document.getElementById("sample").style.color="rgb("+hex+","+hex+","+hex+")";
setTimeout("fadetext()",20); 
}
else
hex=255 //reset hex value
}
</script>
 
 <DIV id="sample" style="position:absolute; left:-05px; top:297px; font-family:verdana; font-size:14px; line-height:21px;" >
  The payoff...<BR>better service for your<BR>customers and greater<BR>profits for you.</I></B>
</DIV>
 
This is what I have.
Code:
<SCRIPT>
var OpLevel = 0;
setInterval("FadeIn(document.object)", 100);

function FadeIn(Object) {
   if (OpLevel <=100) {
      Object.filters.Alpha.Opacity = OpLevel;
      OpLevel +=5;
   } else {
      clearInterval();
   }
}
</SCRIPT>
The opacity value is stored in the OpLevel variable. The 100 is the milliseconds it will take for it to increase it another level (use this to speed it up or slow it down). The 5 is how much it is increased by at each interval. It runs until it reaches OpLevel 100, then stops.
You will need to change the document.object portion to reflect the name of the object.

Hope this helps....then you would still use the onLoad function.

Jenny May
 
that still didn't seem to work, I tested it on its own page and it just does nothing. am I use the object properly??
document.sample??

Code:
<script type="text/javascript">
hex=255 // Initial color value.
function onPageLoad()
{ 
var OpLevel = 0;
setInterval("FadeIn(document.sample)", 100);

function FadeIn(Object) {
   if (OpLevel <=100) {
      Object.filters.Alpha.Opacity = OpLevel;
      OpLevel +=5;
   } else {
      clearInterval();
          }
}}
</script>
  
 <DIV id="sample" style="position:absolute; left:-05px; top:297px; font-family:verdana; font-size:14px; line-height:21px;" >
  The payoff...<BR>better service for your<BR>customers and greater<BR>profits for you.</I></B>
</DIV>
 
Opacity is not the same as fading from black-white (or white-black). It changes the opacity, and will not work in all browsers. ALso, if you don't have a white background, it will also not work correctly.

See ,y post in this thread: thread216-777327 for more details on fading text from white-black or black-white without using opacity.

Hope this helps,
Dan
 
I was kinda like WTF up until I got to Billy's post, rock on Bill!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top