First of all, I don't think you need this:
Code:
<script language="JavaScript">
img1_on = new Image(68,50);
img1_on.src="imageswap.gif";
img1_off = new Image(68,50);
img1_off.src="image.gif";
function over_image(parm_name)
{
document[parm_name].src = eval(parm_name + "_on.src");
}
function off_image(parm_name)
{
document[parm_name].src = eval(parm_name + "_off.src");
}
</script>
because the background images, being smaller will load before the larger images anyway, and neither will be seen until the larger images have loaded. That's what the loadsure (the 'little inline script') script does.
To take care of the issue you are asking about, use this version of the script (additions highlighted):
Code:
/* Expando-ZV Image Script ©2008 - 2009 John Davenport Scheuer
as first seen in http://www.dynamicdrive.com/forums/
username: jscheuer1 - This Notice Must Remain for Legal Use */
if (document.images){
(function(){
var cos, times = 40, speed = 20, etype = null;
var expConIm = function(im){
im = im || window.event;
etype = im.type || null;
if (!expConIm.r.test (im.className))
im = im.target || im.srcElement || null;
if (expConIm.cr.test (im.className) && etype == 'mouseover'){
im.getElementsByTagName('img')[0].style.visibility = 'visible';
im.className += ' start';
return;
}
else if (!im || !expConIm.r.test (im.className))
return;
var e = expConIm,
widthHeight = function(dim){
return dim[0] * cos + dim[1] + 'px';
},
resize = function(){
cos = (1 - Math.cos((e.ims[i].jump / times) * Math.PI)) / 2;
im.style.width = widthHeight (e.ims[i].w);
im.style.height = widthHeight (e.ims[i].h);
if(/\bexcent\b/.test(im.className))
im.style.left = '-' + parseInt(widthHeight (e.ims[i].w)) / 2 + 'px';
if (e.ims[i].d && times > e.ims[i].jump){
++e.ims[i].jump;
im.parentNode.style.zIndex = 3;
e.ims[i].timer = setTimeout(resize, speed);
} else if (!e.ims[i].d && e.ims[i].jump > 0){
--e.ims[i].jump;
im.parentNode.style.zIndex = 2;
e.ims[i].timer = setTimeout(resize, speed);
} else if (!e.ims[i].d && e.ims[i].jump < 1){
im.parentNode.style.zIndex = '';
im.parentNode.className = im.parentNode.className.replace(expConIm.sr, '');
im.style.visibility = 'hidden';
}
}, d = document.images, i = d.length - 1;
for (i; i > -1; --i)
if(d[i] == im) break;
i = i + im.src;
if (!e.ims[i]){
im.title = '';
e.ims[i] = {im : new Image(), jump : 0};
e.ims[i].im.onload = function(){
e.ims[i].w = [e.ims[i].im.width - im.width, im.width];
e.ims[i].h = [e.ims[i].im.height - im.height, im.height];
e (im);
};
e.ims[i].im.src = im.src;
return;
}
if (e.ims[i].timer) clearTimeout(e.ims[i].timer);
e.ims[i].d = !e.ims[i].d;
if(e.ims[i].w && e.ims[i].h)
resize ();
};
document.write('<style type="text/css">.start { background-position: -1000px!important;}.expando {visibility: visible;}<\/style>');
expConIm.ims = {};
expConIm.r = new RegExp('\\bexpando\\b');
expConIm.cr = new RegExp('\\bexcontainer\\b');
expConIm.sr = new RegExp(' start');
if (document.addEventListener){
document.addEventListener('mouseover', expConIm, false);
document.addEventListener('mouseout', expConIm, false);
}
else if (document.attachEvent){
document.attachEvent('onmouseover', expConIm);
document.attachEvent('onmouseout', expConIm);
}
})();
}
Bookmarks