[英]ie6 img width:auto doesn't work
I have an image element which is dynamically changed, and if necessary dynamically re-sized to fit its container. 我有一个图像元素,它是动态更改的,如有必要,可以动态调整其大小以适合其容器。
My current process is: 我当前的流程是:
reset image: 重设图片:
// make sure the 'load' event is re-triggered img.src = ""; // reset dimensions img.style.width = "auto"; img.style.height = "auto";
set its new source and wait for it to load 设置其新源并等待其加载
img.src = newImageSource;
in the images onload
handler, the size is tested and if necessary, altered: 在图像
onload
处理程序中,测试了大小,并在必要时进行了更改:
img.style.width = newWidth + "px";
this is repeated as often as the image is changed (infinite). 每当图像更改(无限)时,重复此操作。
This works fine for all browsers tested (ie7,8,9,10, FF, chrome) however ie6 setting width/height to "auto" seems to resize the element to around 25 x 25 px regardless of the actual image's dimensions. 这对于所有经过测试的浏览器(即7、8、9、10,FF,chrome)都可以正常工作,但是ie6将width / height设置为“ auto”似乎可以将元素的大小调整为25 x 25 px,无论实际图像的尺寸如何。
So; 所以; is there a way to reset the images dimensions to the equivalent of "auto" so that the dimensions of the image subsequently loaded determines the elements dimensions for ie6?
是否有办法将图像尺寸重置为“自动”的等效值,以便随后加载的图像尺寸确定ie6的元素尺寸?
I believe you can write 我相信你会写
img.style.width = "";
to set the width to its default value of auto
. 将宽度设置为其默认值
auto
。 Apparently img.style.width = "auto";
显然
img.style.width = "auto";
doesn't work the same way. 不能以相同的方式工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.