SUPER :) det var lige det der skulle til! Det er testet i IE 6.0, IE 7.0, Firefox 2.0, og Safari Mac. Den endelige kode bliver altså:
<html>
<head>
<script language="javascript" type="text/javascript">
var OpC = new Array();
var ie,moz,css3; function startOpChange(elm,end,tim){
ie = !!elm.filters;
moz = elm.style.MozOpacity != undefined;
css3 = elm.style.opacity != undefined;
if (!ie && !moz && !css3)return;
var idx = OpC.length;
for(var i=0;idx>i;i++){
if(OpC[i][0]==elm){
clearInterval(OpC[i][4]);
idx = i;
break;
}
OpC[idx] = new Array();
}
if(idx==0)OpC[idx] = new Array();
if(ie)actOp=elm.filters.alpha.opacity;
else if(css3)actOp=(elm.style.opacity*100);
else actOp=(elm.style.MozOpacity*100);
if (actOp!=end){
OpC[idx][0]=elm;
OpC[idx][1]=actOp;
OpC[idx][2]=end;
OpC[idx][3]=(end>actOp)?1:-1;
var delayTime = Math.floor((tim*1000)/Math.abs((actOp-end)));
OpC[idx][4]=setInterval("opChange("+idx+")",delayTime);
}
}
function opChange(idx){
OpC[idx][1]+=OpC[idx][3];
if (ie)OpC[idx][0].filters.alpha.opacity=OpC[idx][1];
else if(css3)OpC[idx][0].style.opacity=Math.min(0.99,OpC[idx][1]/100);
else OpC[idx][0].style.MozOpacity=Math.min(0.99,OpC[idx][1]/100);
if (OpC[idx][1]==OpC[idx][2]){
clearInterval(OpC[idx][4]);
return;
}
}
function initFade() {
var oDiv = document.getElementById("test");
startOpChange(oDiv,100,1);
}
</script>
</head>
<body onload="initFade();">
<div id="test" style="width:100%;filter:alpha(opacity=0);-moz-opacity:0.0;opacity:0.0;" onmouseover="startOpChange(this,50,1);">
<div><h1>Fade test</h1></div>
<div><img src="
http://www.eksperten.dk/img/elogo.png" onmouseover="startOpChange(this,100,1);" align="left" style="filter:alpha(opacity=40);-moz-opacity:0.4;opacity:0.4;" />Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nullam ut lectus sit amet lorem consequat congue. Etiam vulputate fringilla erat. Nam ultrices erat vitae felis. Mauris porttitor. Donec ultrices velit ut neque. Curabitur commodo sem nec ligula. Suspendisse lobortis erat dictum lacus. Vivamus dapibus. Nulla sodales sapien sed mauris.</div>
</div>
</body>
</html>