Page 1 of 1

javascript: blinking image problem

Posted: Wed Nov 24, 2004 11:03 am
by newmember
i'm doing some simple effect with js...

Code: Select all

<!--html-->
<img src="images/fire.png" id="fire" />

/*css*/
#fire&#123;
position:absolute;top:140px;left:100px;
display:none;
&#125;

//javascript
delay=100;

timer=window.setInterval("blinkImg()",1000);


function blinkImg()
&#123;
f=document.getElementById("fire");
(a) f.style.display="block";
for(i=1;i<delay;i++) // creates delay between blinks
   dummy=0;
(b) f.style.display="none";
&#125;
above code should create blinking image that blinks fast each single time and there is 1000ms pause between separate blinks
but it doesn't work:image stays not visible...
if i interchange lines (a) and (b) then it works(actually f.style.display="none"; becomes redundent line)
i suspect that there are certain optimizations in js parser that interfere with my code in some way
i tried also to put alert() after each f.style.display line and then script worked as i planned...

does anyone knows what's going on?

Posted: Thu Dec 09, 2004 6:18 am
by DrHoliday
Maybe the parser optimizes the for loop to use no time. You might try use a interval of 500ms, and set the display to "block" if it's "none", and to none if it's "block", without the for loop.

Wolfgang