4

我有一个动态加载图像的.NET 应用程序。在图像加载之前,我会显示加载 gif。然后显示图像。

加载的 gif 图像大小为16x11. 加载的图像都调整为80px宽度。

此代码适用于 IE8-10(但不适用于 IE11):

$(imagesToLoadList).each(function () {

    var image = $(this);
    var realSrc = image.attr('real-src');

    var demandedImageIndex = parseInt(categoryId) + (scrollCount * 10) + index;

    image.unbind();
    image.bind('load', { ImageIndex: demandedImageIndex }, ImageLoaded);
    image.attr('src', realSrc);

    index++;
});

function ImageLoaded(event) {

    //after image loaded 
}

在 IE 11 中,图像会加载,但不会调整大小80px并保持16x11。再次触发事件时,它将正确调整大小。(应用程序有一个滑块,因此每次更改幻灯片时都会调用加载事件)。

有想法该怎么解决这个吗?

仅供参考,图像是否被缓存无关紧要。沿着IE8 错误的思路思考

4

1 回答 1

1

似乎它在 IE 11 中运行良好,即使使用jQuery 1.8.0/ 1.8.3(现在最新的稳定版本是1.11.3/ 2.1.4。单击预览以加载全尺寸图像 - JSFiddle

var $img = $('img');

$img.one('click', function() {
    $img.one('load', function() {
        this.width = 320;
        this.height = 240;
        console.log('Image loaded');
    });

    this.src = $(this).data('large-src');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>

<img src="http://oi59.tinypic.com/nxtdsp.jpg"
     data-large-src="http://oi57.tinypic.com/fegkeb.jpg"/>

如果您将提供带有错误的工作代码片段,也许我可以帮助您。

于 2015-08-11T20:58:58.417 回答