Click to See Complete Forum and Search --> : Handling 'nested' onMouseOver's


Tekime
06-11-2002, 12:55 PM
I have a chunk of code here that's starting to really bug me. I know I ran into this problem in the past, but my resolve escapes me at the moment :(

I re-wrote a very basic version of this code so you can see what's happening:


<div onmouseover="javascript: mainmenu.src = 'gfx/Animation1.gif'" onmouseout="javascript: mainmenu.src = 'gfx/frame01.gif'">
<img src="gfx/frame01.gif" name="mainmenu">
<br>
<a href="#NULL">Option 1</a><br>
<a href="#NULL">Option 2</a><br>
<a href="#NULL">Option 3</a><br>
<a href="#NULL">Option 4</a><br>
</div>


The onmouseover in the div swaps the image with a single-pass animation, basicallly a lighting effect that turns part of it blue.

Now the problem: every time I pass over a link within that div it resets the onmouseover and plays the animation again. Is there any way to avoid this?

Any ideas would be very helpful, I know there is a way but I can't remember if I just did a hack job to get things working before.

Thanks :)

Wollington
06-11-2002, 01:51 PM
I haven't used JS in so long I can hardly remember any of it, therefore this is probably way off mark.

But don't you use "return false;" or "return true;" to stop things like his happening?

Zoma
06-11-2002, 04:45 PM
Try this:

Create two functions, one for onMouseOver and one for onMouseOut. When the first function is called, have it first check a global boolean, "animationStarted." If it is false (which you should set as the default value), set the bool to true and swap images. Otherwise, do nothing. Then have your onMouseOut handling function reset animationStarted to false.

Something like:


<SCRIPT>
boolean animStarted = false;

int mouseOverHandler()
{
if (!animStarted)
{
animStarted = true;
// Do image junk
}
}

int mouseOutHandler()
{
animStarted = false;
// Do image junk
}
</SCRIPT>

Tekime
06-12-2002, 04:07 PM
I'll probably go for something along the lines of what you suggested, Zoma. For some reason I was thinking there would be a way to kill the link focus from interrupting the DIV focus... but your suggestion fixes the problem anyway. Thanks a ton!