Page is a not externally linkable
- Code, Content, and Presentation
-- JavaScript and AJAX
---- Need help with JavaScript


Fotiman - 1:01 pm on Jul 9, 2010 (gmt 0)


The script you have now can be modified to preload the new images like so:


for (id in imgSwap) {
if (imgSwap.hasOwnProperty(id)) {
el = document.getElementById(id);
if (el) {
// Attach event handlers
el.onmouseover = function (el, src) {
return function () {
el.src = src;
};
}(el, imgSwap[id].newImg);
el.onmouseout = function (el, src) {
return function () {
el.src = src;
};
}(el, imgSwap[id].oldImg);
// Preload images
var preloadImg = new Image();
preloadImg.src = imgSwap[id].newImg;
}
}
}


Thread source:: http://www.webmasterworld.com/javascript/4165486.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com