I have a page with 7 gif files on it.
Is there a way to sync them all, so they start playing at the same time?
I was thinking of preloading them, but still they may not start synced if one takes longer to load than another.
I have a page with 7 gif files on it.
Is there a way to sync them all, so they start playing at the same time?
I was thinking of preloading them, but still they may not start synced if one takes longer to load than another.
Share Improve this question asked Oct 12, 2012 at 14:35 williamsongibsonwilliamsongibson 2773 silver badges11 bronze badges 3 |3 Answers
Reset to default 16As @Archer pointed out above, one way to do it is to preload them then reset the src. Using jquery you could do something like:
$(window).load(function() {
$('.preload').attr('src', function(i,a){
$(this).attr('src','').removeClass('preload').attr('src',a);
});
});
See it on jsfiddle.
Consider replacing your gifs with png sequences (sprite sheets), or even jpg sequences, depending on type of content.
Create a div of the desired animation size, set sprite sheet as background image with overflow hidden.
Create a timer in javascript that updates all animations (background image positions) at the same time with each tick allowing you to control the frame rate very precisely.
I've used this technique before and it works well if your sprite sheets are not affecting load times too much.
Try preloading them all in the head of the page and run them when the body loads. Make a function, function gifs{}
maybe, and run it like this: <body onload="gifs()">
.
$("img").each(function() { $(this)[0].src = $(this)[0].src; });
– Reinstate Monica Cellio Commented Oct 14, 2012 at 10:15