sully
sully

Reputation: 31

Jquery Image Load in IE

I have been trying to use a script, which works fine in Chrome and firefox but Jams In IE.

See here http://www.micahcarrick.com/code/jquery-image-swap/index.html

Why does it not Work in Ie, any idea's anyone?

Upvotes: 3

Views: 1229

Answers (1)

jfriend00
jfriend00

Reputation: 708036

In at least some versions of IE, you have to register the load event BEFORE you set the .src property because if the image is in the cache, the load event will fire immediately right when you set .src and thus you will miss it if you haven't already set the .load event handler.

In the jsFiddle code, it would need to be this (also simplified it a bit):

var url = this.href;
$('<img />').load(function() {
    $('#imageWrap').css('background-image', 'none');
    $('#mainImage').attr('src', url).fadeIn();
}).attr('src', url);

You can see it work here: http://jsfiddle.net/jfriend00/vEVVG/

Upvotes: 6

Related Questions