重新启动gif动画,而不重新加载文件 [英] Restart a gif animation without reloading the file

查看:177
本文介绍了重新启动gif动画,而不重新加载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有可能重新启动一个gif动画,而不是每次下载文件?
我当前的代码看起来像这样:

Is it possible to restart a gif animation without downloading the file every time? My current code looks like this:

var img = new Image();
img.src = 'imgages/src/myImage.gif';

$('#id').css('background-image', 'url("' + img.src + '?x=' + Date.now() + '")' );

编辑

当我插入gif到dom,它没有重新启动gif动画。我只能通过在图像src附加一个随机字符串来实现这一点,但这将再次下载图像。

When I insert the gif into the dom it didn't restart the gif animation. I can only achieve this by appending a random string to the image src but this will download the image again.

我想知道是否可以在不下载gif的情况下重新启动gif动画。

I want to know if it is possible to restart the gif animation without downloading the gif.

推荐答案

我也有类似的要求。

var img = document.createElement("img"),
    imageUrl = "http://i73.photobucket.com/albums/i231/charma13/love240.gif";
img.src = imageUrl;
document.body.appendChild(img);

window.restartAnim = function () {
    img.src = "";
    img.src = imageUrl;
}

这篇关于重新启动gif动画,而不重新加载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆