3
votes

i've an animated gif image within a hidden div. Exactly after 7seconds page has loaded the div shows up and hence the image. Now my problem is that when the page is loaded for first time div shows up as it should and gif plays from the beginning but second time onwards it goes mad. When the div shows up gif image plays from somewhere in the middle of animation. any idea?

1

1 Answers

3
votes

Gifs load progressively and start playing as soon as there's enough data to show a whole frame. It's strange that the seconds time it load it should move to the middle.

It's likely because the second time the gif is cached and starts playing right away, and the rest of the page takes some time to load.

You could address this with javascript. At the time you want to start the gif, select the img element and change it's src attribute for the same one. That should trigger a reload so it will start over. And since it's cached, there should be minimal latency.