如何在 HTML 文档中制作 GIF 动画?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38309480/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to animate GIFs in HTML document?
提问by MaryBaker
I have the following <img>
tag in a static HTML document.
我<img>
在静态 HTML 文档中有以下标记。
<img src="foo.gif" alt="This is an animated gif image, but it does not move"/>
After I set its src
attribute to point to a .gif
file (i.e. foo.gif
), the GIF appears as a static (or non-moving) image. How do I animate the GIF?
在我将其src
属性设置为指向.gif
文件(即foo.gif
)后,GIF 显示为静态(或非移动)图像。如何为 GIF 设置动画?
回答by Yuri Tkachenko
By default browser always plays animated gifs, and you can't change that behaviour. If gif image does not animate there can be 2 ways to look: something wrong with the browser, something wrong with the image. Then to exclude the first variant just check trusted image in your browser (run snippet below, this gif definitely animated and works in all browsers).
默认浏览器总是播放动画 gif,你不能改变这种行为。如果 gif 图像没有动画,可以有两种查看方式:浏览器有问题,图像有问题。然后要排除第一个变体,只需在浏览器中检查受信任的图像(运行下面的代码片段,此 gif 肯定是动画的并且适用于所有浏览器)。
Your code looks OK.
Can you check if this snippet is animated for you?
If YES, then something is bad with your gif, if NOsomething is wrong with your browser.
你的代码看起来不错。你能检查一下这个片段是否为你制作了动画吗?
如果YES,那么你的 gif 有问题,如果NO是你的浏览器有问题。
<img src="http://i.stack.imgur.com/SBv4T.gif" alt="this slowpoke moves" width=250/>
回答by EpixyCoder101
try
尝试
<img src="https://cdn.glitch.com/0e4d1ff3-5897-47c5-9711-d026c01539b8%2Fbddfd6e4434f42662b009295c9bab86e.gif?v=1573157191712" alt="this slowpoke moves" width="250" alt="404 image"/>
and switch the src with your source. If the alt pops up, try a different url. If it doesn't work, restart your computer or switch your browser.
并使用您的源切换 src。如果 alt 弹出,请尝试不同的 url。如果它不起作用,请重新启动计算机或切换浏览器。
回答by Steve Gray
I just ran into this... my gif didn't run on the server that I was testing on, but when I published the code it ran on my desktop just fine...
我刚刚遇到了这个……我的 gif 没有在我正在测试的服务器上运行,但是当我发布代码时,它在我的桌面上运行得很好……