在不重新加载文件的情况下重新启动 gif 动画 [英] Restart a gif animation without reloading the file

查看:46
本文介绍了在不重新加载文件的情况下重新启动 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天全站免登陆