在 html 页面中包含一个 gif
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13668792/
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
Including a gif in html page
提问by don
I have no idea why a simple gif image is not being loaded properly. In the html code I have the usual
我不知道为什么没有正确加载简单的 gif 图像。在 html 代码中,我有通常的
<img src="/img/loading.gif" alt="Loading" title="Loading" />
and the file is in that folder. The weird thing is that if I place there /img/logo.png
the image is loaded properly.
并且该文件在该文件夹中。奇怪的是,如果我放在那里/img/logo.png
,图像就会正确加载。
The filename is correct, I've even copied and pasted it renaming the original files.
文件名是正确的,我什至复制并粘贴了它,重命名了原始文件。
PS tested on Firefox 12, Safari 6.0.2 Chrome 23.0.1271.95 (all for Mac)
PS 已在 Firefox 12、Safari 6.0.2 Chrome 23.0.1271.95(全部适用于 Mac)上测试
采纳答案by Sawant
It was probably a corrupt gif. Your code should work with some other gif. If you really want to get the corrupt gif to work, try opening it in an image editor program and then resave it as gif (or any other format).
这可能是一个损坏的 gif。您的代码应该与其他一些 gif 一起使用。如果您真的想让损坏的 gif 工作,请尝试在图像编辑器程序中打开它,然后将其重新保存为 gif(或任何其他格式)。
回答by Mat Richardson
Silly question, but what does your gif look like? Is it transparent, or white against a white background?
愚蠢的问题,但你的 gif 是什么样子的?它是透明的,还是白色背景上的白色?
One possible way to diagnose the problem would be (in Chrome or Firefox), to press F12 to bring up the developer tools and look at your img element to see if the image has loaded in the DOM.
诊断问题的一种可能方法是(在 Chrome 或 Firefox 中),按 F12 以调出开发人员工具并查看您的 img 元素以查看图像是否已加载到 DOM 中。
回答by don
I think the problem was with the gif file, probably somehow broken. I got it from a random resources web site and downloaded from it.
我认为问题出在 gif 文件上,可能以某种方式损坏了。我从一个随机资源网站上得到它并从中下载。
I've tried with a new file got from http://www.ajaxload.info/
now with the code unchanged it works fine.
我已经尝试使用从http://www.ajaxload.info/
现在开始的新文件,代码没有改变,它工作正常。
Edit: the "broken" gif file was working fine elsewhere in the system (e.g. quicklook).
编辑:“损坏的”gif 文件在系统的其他地方运行良好(例如 quicklook)。