本文介绍了在Chrome和Firefox中,动画GIF只会循环一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有一个动画gif,我想要显示一个页面正在加载。当我在浏览器之外查看图像时,图像无限循环并且工作得很好,但每当我在浏览器中显示图像时,动画只会循环一次。有没有人有任何建议,使图像循环无限?



目前我只是这样做,使图像出现,使其出现,但只循环一次:

  document.getElementById('ajaxloader')。innerHTML = 
'< img src =images / ajax- loader.giftitle =正在加载,请稍候...>';


解决方案

前段时间我写的GIF编码器/解码器类(随时间改进)。我昨天才发现这个解决方案。在现代互联网浏览器方面, GIF 是完全正确的。被感染的浏览器是Opera,IE,Chrome(没有测试其他)。

经过对这个问题的一些调查(通过比较循环和非循环图像),我发现这些浏览器 GIF 解码器忽略 GIF 文件中的循环参数。相反,它们依赖于在 GIF 文件的第一帧中的未公开的应用程序扩展。所以解决方案是在第一帧之前添加这个扩展命令帧图像数据。添加这个块:

  0x21,0xFF,0x0B,NETSCAPE,2.0,0x03,0x01,0x00,0x00, 0x00 

这将迫使浏览器无休止地循环播放。



这里的例子:





GIF 对插入/重新排列非图像数据块不敏感,因此您可以在第一张图片之前插入任何其他扩展名之间的任何位置。我把它直接在头+调色板之后。可以用 C ++ 或任何其他语言来完成。 (不需要重新编码)。有关详细信息,请参阅:









[由Reed Dunkle编辑]



您也可以使用十六进制编辑器手动执行此操作。我在macOS Sierra上使用了Hex Fiend。
$ b

在十六进制的起始部分搜索 21 F9 是标题)。在上面的照片中,它是 21 F9 04 04 00 00 00 00 。你可能会有所不同,但注意它在 2C 之前,它标志着一个图像块的开始。



21 F9 ...部分之前,插入以下十六进制,在上图中标记为应用程序扩展名:

  21 FF 0B 4E 45 54 53 43 41 50 45 32 2E 30 03 01 00 00 00 

保存并测试它。



Addon by Spektre:Beware 21 F9 标记gfx扩展块,这是可选的,所以它可能不存在所有或任何帧(但这是真的很罕见)


I have an animated gif that I want to display any time a page is loading. When I view the image outside of a browser, the image loops infinitely and works just fine, but whenever I'm displaying the image in a browser, the animation only loops once. Does anyone have any suggestions for making the image loop infinitely?

Currently I'm just doing this to make the image appear which does make it appear, but only loops once:

document.getElementById('ajaxloader').innerHTML =
    '<img src="images/ajax-loader.gif" title="Loading, please wait..">';
解决方案

I was facing the same problem with my GIF encoder/decoder class I wrote some time ago (and improving with time to time). I found out the solution for this just yesterday. The GIF is completely fine the problem is on modern internet browser's side. Infected browsers are Opera,IE,Chrome (didn't test others).

After some investigation on the matter (by comparing looping and non looping images) I found out that these browsers GIF decoders are ignoring the looping parameters in GIF file. Instead they are depending on undocumented application extension in the first frame of GIF file.

So the solution is to add this extension command just before first frame image data. Add this chunk:

0x21,0xFF,0x0B,"NETSCAPE","2.0",0x03,0x01,0x00,0x00,0x00

This will force browsers to loop endlessly.

Here example:

Hex view so you see how it is added:

The GIF is not sensitive on inserting/reordering non image chunks of data so you can insert this before first image on any place between any other extension. I put it directly after header + palette. Which can be done with C++ or any other language. (no re-encoding is needed). For more info see:


[Edit by Reed Dunkle]

You can also do it manually with a Hex Editor. I used "Hex Fiend" on macOS Sierra.

Search for 21 F9 in the beginning portions of hex (this is the header). In the photo above, it is 21 F9 04 04 00 00 00 00. Yours could be slightly different, but notice it comes before 2C, which marks the beginning of an image block.

Before the 21 F9... portion, insert the following hex, marked as the "application extension" in the photo above:

21 FF 0B 4E 45 54 53 43 41 50 45 32 2E 30 03 01 00 00 00

Save, and test it.

Addon by Spektre: Beware 21 F9 marks gfx extension chunk which is optional so It may not be present for all or any frames (but that is really rare these days)

这篇关于在Chrome和Firefox中,动画GIF只会循环一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 13:55