PDA

View Full Version : mouseover buttons disappear



java joe
07-24-2005, 03:19 AM
I am using the floating menu script at http://www.dynamicdrive.com/dynamicindex1/staticmenu.htm
on a web site at http://www.reflectiontime.com

Some of the buttons will disappear when clicking on them and sometimes the mouseover effect does not work. I have some other java links on same page, and am wondering if there is a conflict with running more than one script.
The floating effect works nicely though.
Thanks for any help on this.
JJ

IanMarlowe
07-24-2005, 04:17 AM
Must be your browser. They work fine on mine.

java joe
07-24-2005, 10:26 PM
I tried viewing the site on a different computer that had high speed internet, and it did once or twice on it, and my customer says it happens quite frequently on her computer, and she live in a different country.
Any clues?

java joe
07-24-2005, 11:13 PM
I got it. Thanks shyam at the Coding Forums. JJ~


i think thats because the body.onload will be called long after the other inline javascript functons calls have been executed. so, if the mouse was already over an image while rollover is being called causes that images source to become undefined.

you can fix this by making imgOrSrc an attribute of the image itself and setting it before the event handler.


Code:
function rollover() {
if (!document.getElementById) return
var imgOrSrc;
var imgPreload = new Array();
var images = document.getElementsByTagName('img');
for (var i = 0; i < images.length; i++) {
if (images[i].getAttribute('rsrc')) {
imgPreload[i] = new Image();
imgPreload[i].src = images[i].getAttribute('rsrc');
images[i].imgOrSrc = images[i].getAttribute("src");
images[i].onmouseover = function() {
this.imgOrSrc = this.getAttribute('src');
this.setAttribute('src',this.getAttribute('rsrc'))
}
images[i].onmouseout = function() {
this.setAttribute('src',this.imgOrSrc)
}
}
}
}