Solved

Using mouseout to close drop-down menu not working properly

Posted on 2013-05-17
4
477 Views
Last Modified: 2013-05-17
My test page:
http://partnersdesign.net

Mouseover the "make contact" text at the top-right, and a menu appears below it. That works fine.

I'm trying to create a smooth, usable mouseout effect. I thought if the user mouses away from the menu, it should close (the actual menu, not the menu's opener "make contact"). This is what I have:

$('#contact').mouseout(function(){
      $('#contact').slideUp(500);
});

However, if you mouseover the "EMAIL" link, that apparently counts as a "mouse out" of the <div> that contains it, and the menu closes prematurely. My markup looks like this:

<a id="contactbtn">MAKE CONTACT</a>
<div id="contact">
      610.488.7611
      <div class="blackline"></div>
      <a href="mailto:info@partnersdesign.net">EMAIL</a>
      <div class="blackline"></div>
      <a href="https://www.facebook.com/pages/Partners-Design-Inc/62221992069?fref=ts" target="_blank">FACEBOOK</a>
</div>

Is there a better way to handle the mouseout so it works more smoothly?

Thank you!
0
Comment
Question by:bbdesign
  • 2
  • 2
4 Comments
 
LVL 26

Expert Comment

by:skullnobrains
Comment Utility
you need to apply cancelBubble() to the event that fires in your a tag
0
 

Author Comment

by:bbdesign
Comment Utility
I'm not following you. How do I modify my script to make the menu slide up at the right time?

$('#contact').mouseout(function(){
      $('#contact').slideUp(500);
});
0
 
LVL 26

Accepted Solution

by:
skullnobrains earned 500 total points
Comment Utility
whatever the problem was, i cannot reproduce it with FF 21 on linux not FF(?) ON BSD nor FF(?) on windows XP

but but the problem should be related with an onmouseover event of the internal A tag rather that whatever problem related to the onmouseout of the DIV
0
 

Author Comment

by:bbdesign
Comment Utility
I ended up doing this:

$('#contact').mouseout(function(){
      if ($('#contact').is(':hover')===false && $('#contacthover1').is(':hover')===false && $('#contacthover2').is(':hover')===false){
            $('#contact').slideUp(500);
      }
});

So now it just checks each element individually to make sure it isn't in a mouseover state... if none are moused over, then it closes the menu.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now