在 IE 中,它不会缩小大图像。事实上,它可以扩展一些但不是全部。我通过设置较小的宽度和高度属性来缩小它们。如何解决?
我是这样做的:
var $image = $('<img/>');
$image.attr('src', 'http://example.com/img.jpeg');
$image.load(function () {
this.width = this.height = 100;
});
类似的东西。但并非所有图像都按比例缩小。而且,每次我重新加载页面时,不同的图像都会按比例缩小。
我查到是怎么回事了。请引用img onload doesn't work well in IE7
IE 6&7 only fire "load" if they actually have to get the image from the server -- they don't if the image is already in local cache.
,杰里米·沃德姆斯写道。
最佳答案
如果您在 html 元素中定义宽度和高度,这应该有效。在 css 中,IE6 不符合标准,结果可能会有所不同。
最佳做法是,您不应在浏览器中调整图像大小,这会降低一切速度并导致像素化。复制所需大小的图像,然后将这些图像链接到全尺寸图像(如果合适)。
完成后,请将这些图像远离我,非常感谢。
关于html - IE中的Image onLoad问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4946441/