iamjpg / Ez-Background-Resize

Resizable full-browser background image using jQuery. Implementation requires no CSS.
http://johnpatrickgiven.com/jquery/background-resize/
89 stars 32 forks source link

Compatibility fix: Set 'load' handler prior to 'src' attribute. #7

Open hayesgm opened 13 years ago

hayesgm commented 13 years ago

Major (and simple) browser compatibility fix for IE when background image is cached.

As per http://www.thefutureoftheweb.com/blog/image-onload-isnt-being-called, setting 'src' attribute on a cached image in IE will instantly fire 'load' event. Thus, as we currently set the 'src' prior to 'bind', we will cause an event handler to be setup after the event (load) has already been triggered. This causes a complete breakdown of ezBgResize on IE8 (and likely other versions / browsers). Simply setting the binding prior to the source fixes this issue.