html - IE中的Image onLoad问题

标签 html css internet-explorer

在 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/

相关文章:

javascript - 在 Google Charts 中使用 JSON 创建数据表

css - 从 css 网格中 react 组件

jquery - 通过jquery为多个div设置css left?

css - html 条件语句 hack 在实时时将 IE 视为错误版本

html - 我的网站在 IE8、IE9 中卡在右边

internet-explorer - Windows PowerShell的IE自动化

html - 不索引部分 HTML

javascript - 移动设备上 CSS 中的背景定位

javascript - Accordion 面板重叠在选择一个之前打开的(第二个)面板上

javascript - 如何使用jquery使用 'data-id'属性更改innerHtml内容?