html - Setting GIF loop count and publishing stop event using JavaScript - Stack Overflow

Is it possible to set the loop count of a GIF image using JavaScript and then publish an event when it

Is it possible to set the loop count of a GIF image using JavaScript and then publish an event when it stops playing?

For example something like:

//html code
<img src="myImage.gif" id="img1"/>

//Javascript code
var image = document.getElementById('img1');

//Image must stop playing after 3 loops
image.setLoopCount = 3;

Is it possible to set the loop count of a GIF image using JavaScript and then publish an event when it stops playing?

For example something like:

//html code
<img src="myImage.gif" id="img1"/>

//Javascript code
var image = document.getElementById('img1');

//Image must stop playing after 3 loops
image.setLoopCount = 3;
Share Improve this question edited Sep 1, 2022 at 21:26 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Nov 17, 2011 at 13:59 DracoDraco 16.4k23 gold badges81 silver badges94 bronze badges 1
  • The answer is "No, not using JavaScript and an actual animated GIF". All the answers so far are helping you with alternatives, but are forgetting to provide this fundamental answer. – Phrogz Commented Nov 17, 2011 at 19:05
Add a ment  | 

2 Answers 2

Reset to default 3

here is how i would suggest doing it:

  • extract frames form gif file (you can do it online using for instace -> http://imgops./)
  • use javascript to change pictures, simulating animation (that way you can keep track of how many loops you have done)

Here is a jsFiddle link http://jsfiddle/qustosh/n5zWH/9/ I used jQuery. I did three loops and i threw a callback function at the end.

For a design side solution, you can set the GIF image to only loop a certain number of times with Photoshop. Then just use window.setTimeout(callback, milliseconds) to trigger your custom event.

You can calculate the time out from the interval used to display each frame of the animation.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745293098a4620979.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信