Issue with Show/Hide on hover (or mouseover/mouseout)
Hi,
I have an issue with a show/hide effect on a menu (list based) triggered with a hover event.
Here is the part of the HTML :
- <div class="somm">
- <ul>
- <li><a href="#tech">2. Aspects techniques</a>
- <ul>
- <li><a href="#gmapi">2.3. L'API JavaScript Google Maps</a>
- <ul>
- <li><a href="#gmapipres">Présentation et « initialisation »</a></li>
- <li class="parent"><a href="#gmapiprem">Premiers pas</a>
- <ul>
- <li><a href="#gmapiprem1">Carte & marqueur</a></li>
- <li><a href="#gmapiprem2">Afficher une infobulle</a></li>
- <li><a href="#gmapiprem3">Fonction pour créer les marqueurs</a></li>
- </ul>
- </li>
- <li class="parent"><a href="#gmapimark">Manipulation avancée des marqueurs</a>
- <ul>
- <li><a href="#gmapimark1">Marqueurs et icones</a></li>
- <li><a href="#gmapimark2">Marqueurs déplaçables</a></li>
- <li><a href="#gmapimark3">GMarkerManager</a></li>
- </ul>
- </li>
- <li class="parent"><a href="#gmapipoly"><em>Polygons</em> & <em>Polylines</em></a>
- <ul>
- <li><a href="#gmapipoly1">GPolyline & GPolygon Overlay Classes</a></li>
- <li><a href="#gmapipoly2">Fichiers KML</a></li>
- <li><a href="#gmapipoly3">Encoded polylines and polygons</a></li>
- </ul></li>
- </ul></li>
- </ul></li>
- </ul>
- </div>
Here is the code with a hover event :
- jQuery(document).ready(function(){
- jQuery(".parent ul").hide();
- jQuery(".parent").hover(function () {
- jQuery(this).children("ul").toggle("slow");
- });
- });
You can test it here : http://jsfiddle.net/wHbah/
The effet is produced when you hover one of the three last items of the list.
As you can see there is a problem when there are multiple and repetitive hover.
I tried to use another code, based on mouseover and mouseout events :
- jQuery(document).ready(function(){
- jQuery(".parent ul").hide();
- jQuery(".parent").mouseover(function () {
- jQuery(this).children("ul").show("slow");
- });
- jQuery(".parent").mouseout(function () {
- jQuery(this).children("ul").hide("hide");
- });
- });
See it in action : http://jsfiddle.net/wHbah/1/
But it's even worth that my first attempt :/
If I try to remove the duration in both that examples, the issue doesn't show as you can see there :
- with the toggle effect : http://jsfiddle.net/wHbah/2/
- with the hide/show effect : http://jsfiddle.net/wHbah/3/
Someone on the irc channel gives me a tip, using the .stop().toggle() but it doesn't solve the issue (make it worse in fact), as you can see there : http://jsfiddle.net/gD742/3/
It seems that using stop(true,true) instead of stop() makes it better : http://jsfiddle.net/wHbah/4/ but there is still a little latency when you don't wait until the sub-menu is entirely shown.
Finally, someone else on the irc channel, gave me that piece of code :
- jQuery(this).children("ul").each( function (index) { jQuery(this).hide();
but I don't really understand what to do whith that.
Thanks you for having read me (sorry for my english) and thanks in advance for your help.
See you