javascript: blinking image problem

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
User avatar
newmember
Forum Contributor
Posts: 252
Joined: Fri Apr 02, 2004 12:36 pm

javascript: blinking image problem

Post 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?
DrHoliday
Forum Newbie
Posts: 11
Joined: Mon Dec 06, 2004 5:12 pm
Location: Germany

Post 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
Post Reply