Forum Moderators: open

Message Too Old, No Replies

Help with IE opacity / timing

         

Skier88

8:27 pm on Feb 15, 2010 (gmt 0)

10+ Year Member



I wrote this code for a fading image slideshow which works great in FF, chrome, opera, and safari. But in IE it goes crazy. It fades in as intended, and the first fade works, and after that it sometimes works, but usually flickers back and forth between two images very rapidly, using a lot of processing power all the while.

I am pretty sure the problem is in the IE portion of the setTrans and/or getTrans function (the switch works).


<script type='text/javascript'>
var browser=navigator.appName.indexOf('Microsoft');
document.write("<div style='width:960px; height:500px;'><div id='r2' style='position:absolute;'></div><div id='r1' style='position:absolute;'></div></div>");
var images = new Array();
images[0]=['images/1.jpg','#'];
images[1]=['images/2.jpg','#'];
images[2]=['images/3.jpg','#'];
images[3]=['images/4.jpg','#'];
var i=0;
var r1 = document.getElementById('r1'); var r2 = document.getElementById('r2');
function getTrans(obj) {if(browser<0) return obj.style.opacity*100; return parseFloat(obj.style['filter'].substring(14,obj.style['filter'].indexOf(')')));}
function setTrans(obj,value) {if(browser<0) obj.style.opacity=value/100; else obj.style['filter']='alpha(opacity='+value+')' ;}
function fade()
{
setTrans(r1,getTrans(r1)+4);
if(getTrans(r1)<100) return;
clearInterval(fading);
i++; if(i==images.length) i=0;
r2.innerHTML='<a href="'+images[i][1]+'"><img src="'+images[i][0]+'"/></a>';
setTimeout('var tmp=r2.innerHTML; r2.innerHTML=r1.innerHTML; setTrans(r1,0); r1.innerHTML=tmp; var fading=setInterval("fade();",15)',5000);
}
setTrans(r1,0); r1.innerHTML='<a href="'+images[i][1]+'"><img src="'+images[i][0]+'"/></a>'; var fading=setInterval("fade();",15);
</script>
<noscript><a href='#'><img src='images/1.jpg'/></a></noscript>


Thanks for looking.

Skier88

7:28 pm on Feb 21, 2010 (gmt 0)

10+ Year Member



I fixed this, so never mind. The issue was the "<" sign - I think IE was treating it as another open tag.