开发者

load event with jquery fails in IE 8

开发者 https://www.devze.com 2023-02-08 19:56 出处:网络
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:

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.fi开发者_Go百科nd(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


Set the load handler first, then set the src.

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


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>

0

精彩评论

暂无评论...
验证码 换一张
取 消