内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用
我在IMG标记中有一个动画gif,我从重写src属性开始。但是,gif是为了循环而创建的,我只想让它播放一次。有什么方法,使用Javascript或jQuery,阻止动画gif播放不止一次?
伪码:
wait until the end of the image (when it is about to loop) create a canvas element that has a static version of the gif as currently displayed drawn on it hide gif display canvas element in a way that makes it look like the gif froze
JavaScript:
var c = $("canvas")[0]; var w = c.width; var h = c.height; var img = $("img")[0]; setTimeout(function () { c.getContext('2d').drawImage(img, 0, 0, w, h); $(img).hide(); $(c).show(); },10000);