创建空的 1px 图像
create empty 1px image
我在 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 它工作。
是否可以在不使用任何文件(png、jpg、...)的情况下设置 1px 透明图像
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>
我在 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 它工作。
是否可以在不使用任何文件(png、jpg、...)的情况下设置 1px 透明图像
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>