gif iterations demo

Demo of Gifs ability to stop iterating after specific number of iterations.

by Jurijs Kovzels

HTML

<h1>
Demo of Gifs ability to stop iterating after specific number of iterations.
</h1>
<p>
  The number of iterations should be specified when gif is created.
</p>

This gif will loop only two times.
<br/>
<img id="twoTimesGif" src="http://i.stack.imgur.com/PUSIu.gif" />
<br/> Animation can can be restarted by reasigning image src property <code>imgElem.src = imgElem.src;</code>
<br/>
<br/>
<input value="Restart animation" type="button" id="resetButton" />
<br/>
<br/> But, restart does not work in IE/Edge

JavaScript

var resetAnimation = function resetAnimation() {
  var twoTimesGif = document.getElementById("twoTimesGif");
  twoTimesGif.src = twoTimesGif.src;
};
var resetButton = document.getElementById("resetButton");
resetButton.addEventListener("click", resetAnimation);