views:

137

answers:

1

I am having a problem with IE6 image swapping using jQuery (but assumedly any old javascript will trigger this issue)

When setting $().attr('src','image.png') where the current image for the selector is drastically different in dimensions to the image.png image, IE6 squeezes the new image into the frame of the old image without resizing at all.

I've tried a few ways around this such as replaceWith on the image with a new image element triggered by an onload event when loading the new image, but nothing seems to be reliable at all, various results have been the image crammed into a very small box, or the new image simply not loading at all.

Any assistance much appreciated.

A: 

Maybe you have to trigger a reflow. Try adding and immediately removing a DIV after the new image has loaded. There must be some better method to trigger a reflow, though. I'll look into it.


Of course I'm assuming you didn't set the image size explicitly with CSS? Because if the img has style="width: 200px; height: 200px;" it will remain a 200px square even if you load a full size render of the Empire State Building into it.


About other ways of triggering a reflow, look here. Let me know if I guessed right.

Kaze no Koe
A better method of triggering a reflow is to set the `className` attribute; you don't even have to modify it. `element.className = element.className` will do it :-) (Note that this may have to be done on a container element, rather than on the image.)
NickFitz
+1 because your answer to my answer is cooler than my answer to his question :D
Kaze no Koe