【问题标题】:create empty 1px image创建空的 1px 图像
【发布时间】:2016-07-22 01:21:30
【问题描述】:

我在 HTML 中创建图像标签

var img = document.getElementById('image');
alert(img.width)
<div width="500">
  <img id="image" width="100%" height="1"></img>
</div>

在所有浏览器中 img.width 将为 500px。但是在 Firefox 中它会是 0。但是如果在图像标签中设置 src 就可以了。

是否可以在不使用任何文件的情况下设置1px透明图像(png,jpg,...)

【问题讨论】:

标签: image firefox size width


【解决方案1】:

var img = document.getElementById('image');
alert(img.width)

Thanx to LinuxDisciple I found a solution to the problem
<div width="500">
  <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" id="image" width="100%" height="1"></img>
</div>

【讨论】:

    猜你喜欢
    • 2011-04-09
    • 2016-06-27
    • 2023-03-20
    • 1970-01-01
    • 2012-06-05
    • 2010-09-19
    • 2020-07-01
    • 2017-09-24
    • 2018-09-26
    相关资源
    最近更新 更多