load event with jquery fails in IE 8

心不动则不痛 提交于 2020-01-29 06:40:25

问题


i've written a jquery plugin to scale a image up an back down. in ie 8 the load event of the large version of the image fails. i tried like thsi:

        var fullImage = container.find(options.fullSelector);
        fullImage.attr('src', fullImageUrl).bind('load', function() {
            content.fadeOut(options.fadeSpeed, function(){
                if(slideContent.size()){
                    slideContent.slideUp(options.resizeSpeed, function(){
                        smallImage.hide();
                        fullImage.show();
                        fullImage.parent().andSelf().stop().animate({ width: options.fullWidth + 'px' }, options.resizeSpeed);
                    });
                }
                else{
                    smallImage.hide();
                    fullImage.show();
                    fullImage.parent().andSelf().stop().animate({ width: options.fullWidth + 'px' }, options.resizeSpeed);
                }
            });
        });

the error says: Object doesn't support property or method.

what am i doing wrong?

thank you


回答1:


Set the load handler first, then set the src.

fullImage.bind('load', function() {
   ...
}).attr('src', fullImageUrl);



回答2:


What about this?

var test = function($what) {
  $('#debug').html('Image loaded: '+$what.width+' x '+$what.height);
  console.log($what);
};
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
// Random image
var src = "http://placehold.it/300x" + Math.round(Math.random() * (310 - 100) + 100);
</script>
<div id="debug">Image loading:</div>    
<img onload="test(this)" id="img" />

<script>
$('#img')[0].src = src;
</script>


来源:https://stackoverflow.com/questions/4921712/load-event-with-jquery-fails-in-ie-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!