Solved

Desync two IMG tags using same animated GIF file

Posted on 2003-12-12
2
525 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now