My fiddle https://jsfiddle.net/baz3ynt1/9/ is the answer using javascript to asynchronously load the image, but then adding them to the DOM at the same time to start the animation synchronously. I do not think that you can force the browser to finish loading the image at a certain time, since the browser cannot know how long it will take to load the resource.
Each GIF is loaded using
gif = new Image();
gif.src = 'image url';
gif.onload = handleLoading();
and the function handleLoading()fires the function startAnimation()as soon as all Gifs fire their event onload:
function handleLoading()
{
numLoadedGifs++;
if (numLoadedGifs === gifUrls.length)
{
startAnimation();
}
};
Then the function startAnimation()adds the previously created elements img(stored in the array) as children on <div id="animation">, but in order to make them work at the same time, the attribute srcgets reset and set it again:
function startAnimation()
{
var animationDiv = document.getElementById('animation');
for (var index in gifList)
{
var img = animationDiv.appendChild(gifList[index]);
img.classList.add('cloth');
img.src = '';
img.src = gifUrls[index];
}
};
Firefox IE 11 ( src - , IE 11).
: , IE , , reset src , https://jsfiddle.net/baz3ynt1/10/ :
function startAnimation()
{
var animationDiv = document.getElementById('animation');
for (var index in gifList)
{
var img = animationDiv.appendChild(gifList[index]);
img.classList.add('cloth');
}
for (var index in gifUrls)
{
gifList[index].src = '';
gifList[index].src = gifUrls[index];
}
};