OK, little has changed from your, the user's, point of view but, those changes are important! You cannot use a destination opacity greater than 99 because FF and other Mozilla based browsers cannot handle it. Fortunately, 99 is so close to 100 that no one will be able to tell the difference by just looking. The other change you need to pay attention to is in the style for for the elements that you want to apply this to. It has been expanded to cover other browsers:
Code:
style="filter:alpha(opacity=10);-moz-opacity:0.10;opacity:0.10;"
Here is the script, tested in FF1.0.7, NS7.2 and IE6. It degrades well in OP8, which has no opacity support, should do the same in other modern browsers that lack such support, and should work in browsers that support style.opacity as well.
Code:
<html>
<head>
<title></title>
<script type="text/javascript">
/*
Gradual-Highlight Image Script II-
By J. Mark Birenbaum (birenbau@ugrad.cs.ualberta.ca)
Permission granted to Dynamicdrive.com to feature script in archive
For full source to script, visit http://dynamicdrive.com
Modified here by jscheuer1 in http://dynamicdrive.com/forums/
to work with Mozilla and other opacity compliant browsers
in addition to the original IE functionality
*/
nereidFadeObjects = new Object();
nereidFadeTimers = new Object();
/* object - image to be faded (actual object, not name);
* destop - destination transparency level, use 0 to 99 (ie 80, for mostly solid, set no higher than 99)
* rate - time in milliseconds between trasparency changes (best under 100)
* delta - amount of change each time (ie 5, for 5% change in transparency)
*/
function sourceNum(obj){
if ((document.documentElement.sourceIndex*1)+1)
return obj.sourceIndex;
else if (document.getElementsByTagName)
var order=document.getElementsByTagName('*')
for (var i_tem = 0; i_tem < order.length; i_tem++)
if (order[i_tem]==obj)
return i_tem;
}
function nereidFade(object, destOp, rate, delta){
if (object.toString().indexOf('object') == -1){ //do this so I can take a string too
setTimeout("nereidFade("+object+","+destOp+","+rate+","+delta+")",0);
return;
}
if (!(object.filters||object.style.MozOpacity||object.style.opacity))
return;
var objOpac=object.filters? object.filters.alpha.opacity : object.style.MozOpacity? object.style.MozOpacity*100 : object.style.opacity? object.style.opacity*100 : null
clearTimeout(nereidFadeTimers[sourceNum(object)]);
diff = destOp-objOpac;
direction = 1;
if (objOpac!==null&&objOpac > destOp){
direction = -1;
}
delta=Math.min(direction*diff,delta);
if (object.filters)
object.filters.alpha.opacity+=direction*delta;
else if (object.style.MozOpacity)
object.style.MozOpacity=(object.style.MozOpacity*1)+(direction*delta/100);
else if (object.style.opacity)
object.style.opacity=(object.style.opacity*1)+(direction*delta/100);
objOpac=object.filters? object.filters.alpha.opacity : object.style.MozOpacity? object.style.MozOpacity*100 : object.style.opacity? object.style.opacity*100 : null
if (objOpac!==null&&objOpac != destOp){
nereidFadeObjects[sourceNum(object)]=object;
nereidFadeTimers[sourceNum(object)]=setTimeout("nereidFade(nereidFadeObjects["+sourceNum(object)+"],"+destOp+","+rate+","+delta+")",rate);
}
}
</script>
</head>
<body>
<img style="filter:alpha(opacity=10);moz-opacity:0.10;opacity:0.10;" onmouseover="nereidFade(this,99,30,5)" onmouseout="nereidFade(this,10,50,5)" src="some.jpg" width="100" height="25" border="0" alt="" title="" />
</body>
</html>
Bookmarks