javascript - 动画 gif 在 Firefox 中不重新启动(示例)

标签 javascript jquery html firefox caching

问题描述:

在许多情况下,动画 gif 在 Firefox 中似乎无法正常重启。这个问题我只在 Mozilla 中遇到过,没有其他浏览器。

例如,为什么this总是重新启动它,但是 this才不是?在后者中,gif 显然被缓存并在后台永远循环,所以当您调用 .show() 时,它会出现在动画中间的某个随机点。

我怎样才能实现我在第二个 fiddle 中尝试做的事情,并在每次隐藏它时强制 gif 重新启动?不,我不想每次都重新下载整个 gif,因此将 '?random=' + Date.now() 附加到图像不是解决方案。

代码来自Link #1 :

$('#still, #animated').click(function() {
    animated.attr('src', "");
    animated.attr('src', srcToGif);
});

代码来自Link #2 :

$('#still, #animated').click(function() {
    if (!clicked) {
        clicked = 1;
        animated.attr('src', "");
        animated.attr('src', srcToGif);
        animated.show();
        setTimeout(function() {
            animated.hide();
            clicked = 0;
        }, 9500);
    }
});

最佳答案

替换

animated.attr('src', "");

animated.removeAttribute('src');

适用于 Firefox 30。 假设单词 animated 是一个普通的、非 jquery 特定的 img 引用。

我一般不做js库,因为我想有控制权。由于库的体积,缩小通常是虚幻的,而且当确实发生异常时,很难进行故障排除。

关于javascript - 动画 gif 在 Firefox 中不重新启动(示例),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22331655/

相关文章:

html - Bootstrap Navbar 不可点击

javascript - Blaze Spacebars Each - 预览下一个和上一个项目

javascript - 直接修改字符串的元素

javascript - 如何在 jQuery 中按值对子项进行排序

html - CSS:当我尝试单击显示列表中的元素时,下拉菜单消失

javascript:使用 getElementByID 填充多个 div

javascript - 使用 jquery 操作 css "content: attr(data-tooltip)"

javascript - 未捕获的 SyntaxError : Unexpected token U in JSON at position 0 at JSON. 解析 (<anonymous>) 在 Response.Body.json

Jquery 脚本路障 : how to show/hide multiple images across multiple divs?

javascript - jquery click 不锁定 bootstrap col-md div