Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

load event with jquery fails in IE 8

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

like image 550
luksak Avatar asked Feb 07 '11 13:02

luksak


2 Answers

Set the load handler first, then set the src.

fullImage.bind('load', function() {
   ...
}).attr('src', fullImageUrl);
like image 120
RoToRa Avatar answered Oct 16 '22 06:10

RoToRa


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>
like image 44
FDisk Avatar answered Oct 16 '22 07:10

FDisk