Solved

Desync two IMG tags using same animated GIF file

Posted on 2003-12-12
2
530 Views
Last Modified: 2013-11-19
A colleague asked me this question, which I thought was easy until I tried to provide him an answer!  :-)

He has an HTML file that contains (among other things) two different <IMG> tags which both use the same animated GIF file as the image source.  Of course, the browser plays the GIF animations in sync.  But that's not what he wants.  (He is correct in saying that the synchronization between the two images is somewhat distracting.)

I'm probably going to have to dig up a GIF editor in my spare time (yeah, right) and build him a separate GIF that animates at a different pace and starting point, but that will probably be time-consuming.

Is there an attribute of the IMG tag, or a JavaScript trick I can use to get the two tags to desynchronize?  (Play at a different rate, or start at a different frame, or both?)

I've looked in some of my HTML documentation and the only thing I've found are the "loop" and "loopdelay" attributes, which I believe only work with AVI's, not GIF's.


Thanks in advance!
    -- outerJoin
0
Comment
Question by:outerJoin
2 Comments
 
LVL 33

Accepted Solution

by:
snoyes_jw earned 125 total points
ID: 9929587
Maybe use JavaScript to load the gif, set one of the image sources to something that is NOT the animated gif, then after some delay, change the src?

Like this (from http://forums.devshed.com/archive/1/2002/10/2/45235)
<head>
<script>
function changeImage() {
    var gifAnimated = 'animated_gif_source_here'
    document.getElementById('animation').src = gifAnimated;
}
</script>
</head>
<body onload = "setTimeout(changeImage,'5000')";>
<img id="animation" width="200" height="200" alt="image">
</body>
0
 
LVL 1

Author Comment

by:outerJoin
ID: 9929855
Ba-BAM!  It *does* work.

I was cringing at the thought that it would probably just delay the start, but that the browser would still start all the GIFs cycling on the same boundary.

But it worked -- the cycle starts when the image gets switched out by the JavaScript.

The GIFs still cycle at the same rate, but at different starting points.

It looks to me like that is going to be enough to break up the visual distraction on the page.  [If my colleague wants more than that, I may just gently suggest he learn to use a GIF editor and build some edited copies of his original image. :-) ]

Thanks!
    -- outerJoin
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question