Handling 'nested' onMouseOver's

Sharky Forums


Results 1 to 4 of 4

Thread: Handling 'nested' onMouseOver's

  1. #1
    Hammerhead Shark Tekime's Avatar
    Join Date
    Dec 2001
    Location
    Falmouth, ME
    Posts
    2,347

    Handling 'nested' onMouseOver's

    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:

    Code:
    <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
    Stuff and stuff

  2. #2
    Tiger Shark
    Join Date
    Mar 2001
    Location
    Staffordshire, UK
    Posts
    963
    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?

  3. #3
    Tiger Shark
    Join Date
    Mar 2001
    Posts
    615
    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:

    Code:
    <SCRIPT>
     boolean animStarted = false;
    
     int mouseOverHandler()
     {
      if (!animStarted)
      {
        animStarted = true;
        // Do image junk
      }
     }
    
     int mouseOutHandler()
     {
      animStarted = false;
      // Do image junk
     }
    </SCRIPT>
    System specs:


    | Core i5 750 | GA-P55A-UD3 | 4.0 GB G.skill DDR3 1600 | eVGA 470 GTX |
    | Intel X25-M 80 GB SSD | WD 5000AAKS | Lian Li PC-7FN | Corsair TX750W |
    | Windows 7 Home 64-bit |

  4. #4
    Hammerhead Shark Tekime's Avatar
    Join Date
    Dec 2001
    Location
    Falmouth, ME
    Posts
    2,347
    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!
    Stuff and stuff

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •