Forum Moderators: open
Any help would be greatly appreciated.
(using IE at the moment...)
<html><head><script language="JavaScript">
//fades layer in
ie5 = (document.all && document.getElementById);
ns6 = (!document.all && document.getElementById);
opac = 0;function fadein(ln) {
alert(ln);
if(opac!= 100){
opac+=5;
if(ie5) document.getElementById(ln).filters.alpha.opacity = opac;
if(ns6) document.getElementById(ln).style.Mozopacity = opac/100;
setTimeout('fadein(eval(ln))', 1);
}
}</script>
</head><body>
<a href="javascript://" onmouseover="fadein('mylayer');">test</a>
<div id="mylayer" style="position:absolute; left:100px; top:150px; width:100px; height:100px; clip:rect(0,100,100,0); filter: alpha(opacity=0); -moz-opacity:0%; background-color:red; z-index:1">
</div></body></html>
1. The statement to execute must be a string (..although this can be done another way).
2. The statement is excuted in a globaol context. This means that none of your local variables are recognized. They must be passed through as strings.
Because ln isn't understood as a variable, it's value must be used. It should then be quoted. Then reason for this is that we want to execute a statement that looks, not like this:
fadein(ln) but
fadein('_valueOfLn_') So it goes like this.
I have changed the condition to <, so the increment doesn't need to be a factor of 100 to work. The setting of MozOpacity statement has some changes too:
ie5 = (document.all && document.getElementById &&!window.opera);
ns6 = (!document.all && document.getElementById);
opac = 0;function fadein(ln)
{
if(opac < 100)
{
opac+=5;
if(ie5) document.getElementById(ln).filters.alpha.opacity = opac;
if(ns6) document.getElementById(ln).style.MozOpacity = opac + "%";
setTimeout("fadein('"+ln+"')", 1);
}
}
--
edited:
Changes to Moz statement
Opera not considered IE5
--
<html><head>
<script language="JavaScript">
//fades layer in
ie5 = (document.all && document.getElementById);
ns6 = (!document.all && document.getElementById);
opac = 0;function fadein(ln)
{
if(opac < 90)
{
opac+=5;
if(ie5) { document.getElementById(ln).filters.alpha.opacity = opac; setTimeout("fadein('"+ln+"')", 1);}
if(ns6) { document.getElementById(ln).style.MozOpacity = opac / 100; setTimeout("fadein('"+ln+"')", 20);
}
}
}</script>
</head><body>
<a href="javascript://" onmouseover="fadein('mylayer');">test</a>
<div id="mylayer" style="position:absolute; left:100px; top:150px; width:100px; height:100px; clip:rect(0,100,100,0); filter: alpha(opacity=0); -moz-opacity:0; background-color:red; z-index:1">
</div></body></html>
<added>I changed the ending opacity to 90 because my intention is to use this for a drop down navigation menu and I wanted the content underneath to show through ever so slightly when fully faded in.
The site is for a magic 8-ball knockoff that I did when I was particularly bored a few months ago.