Pregunta

I have an animated gif and i want to show it on a webpage but show it starting in the middle of the animation (not from the beginning. is this possible?

¿Fue útil?

Solución

It wouldn't be possible in a reliable way I'd imagine. Waiting any amount of time would be dependent on the GIF being rendered consistently and on time.

For more flexibility, make the GIF a spritesheet and cycle through offsets with JavaScript. Then you could start it whenever you like. Something like this...

var imgContainer = document.getElementById("image");
var offset = 0;
setInterval(function() { 
    imgContainer.style.backgroundPosition = (offset % 1000) + "px 0";
    offset += 300; 
}, 1e3);

Otros consejos

It's not clear that your animation will be hidden at the beginning or not.

First of all you need to figure out how many seconds you want to skip. Code bellow shows an Image after 1 seconds.

   //Grab The Image 
    var gifConatainer =  document.getElementById("gifImage");

    // Hide The Image
    gifConatainer.style.display = 'none';

    //Show It After 1000 millisecond 
    setTimeout(function() {
     gifConatainer.style.display = 'block';
    }, 1000);

You can wrap a this with setInterval method to do this process repeatedly after certain times.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top