Invoking an animated gif at random intervals

S

Salmo Bytes

I want to make an animated gif that runs through one loop
and then stops. But I want to invoke it at random time
intervals...so, for instance, a tight head shot
of a person's face winks at the viewer once or twice per minute,
at unpredictable intervals.

I think I could figure out how to use rand() and setTimeout(...)
to create the random time intervals, but I'm not sure about
how to start the one-loop animated gif. Would I have to reload
the whole page? Or is there someway to restart the gif animation
*without* reloading the whole page?....probably not, the more I
think about it.
 
I

Ivo

to create the random time intervals, but I'm not sure about
how to start the one-loop animated gif. Would I have to reload
the whole page? Or is there someway to restart the gif animation
*without* reloading the whole page?....probably not, the more I
think about it.

Don't think about it, but try it:
<img id="pic" src="yourpic.gif">
<input type="button" value="klik"
onclick="document.images.pic.src=document.images.pic.src"The image can be reloaded individually simply by re-setting its src.
HTH
Ivo
 
T

Thomas 'PointedEars' Lahn

Salmo said:
I want to make an animated gif that runs through one loop
and then stops. But I want to invoke it at random time
intervals...so, for instance, a tight head shot
of a person's face winks at the viewer once or twice per minute,
at unpredictable intervals.

I think I could figure out how to use rand() and setTimeout(...)

There is no rand() function. Maybe you mean something
user-defined that calls Math.random().
to create the random time intervals, but I'm not sure about
how to start the one-loop animated gif.

You could try to assign the value of the "src" property
of the respective (HTML)Image(Element) object to itself.

var img = document.images["foobar"]
img.src = img.src;
Would I have to reload the whole page?
Possibly.

Or is there someway to restart the gif animation
*without* reloading the whole page?....probably
not, the more I think about it.

The script engine does not know about images, it only knows
about objects and properties. (HTML)Image(Element) objects
are host objects, it is up to the UA to decide what to do.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,263
Messages
2,571,064
Members
48,769
Latest member
Clifft

Latest Threads

Top