繁体   English   中英

AngularJS加载图像指令setTimeout IE 10问题

[英]AngularJS loading image directive setTimeout IE 10 issue

问题:当用户加载页面时,页面上的某些图像仍在处理中(基本上,图像尚不知道网址)。

解决方案:我创建了指令以显示加载微调器占位符而不是图像,并且setTimeout尝试从该位置加载图像,直到成功为止,如下所示:

myApp.module.directive('errSrc', function () {
return {
    link: function (scope, element, attrs) {
        element.bind('error', function () {
            element.hide();
            $('#loading_image_placeholder_' + element.attr('id')).show();
            setTimeout(function () {                    
                element.attr('src', attrs.src)
            }, 3000);
        });

        element.bind('load', function () {                
            element.show();
            $('#loading_image_placeholder_' + element.attr('id')).hide();
        });
    }
}});

我这样用

<img ng-src="/some/not_yet_avaliable/url_to_image.jpg" err-src id="someId"/>

问题:此解决方案在FF,Safary和Chrome中运行良好,但是当我在IE10和IE 11中进行测试时,“错误”事件正确执行,但从未执行“加载”事件。 IE只是一直试图在setTimeout中设置src属性,但是由于某些原因,当图像不再损坏时,它永远不会绑定“加载”。

IE的解决方法是添加:

element.attr('src', attrs.src + "?" + new Date().getTime())

根据评论中的链接http://css-tricks.com/snippets/jquery/fixing-load-in-ie-for-cached-images/

谢谢!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM