tags:

views:

48

answers:

1

The following code works successfully, except the menu slideDown only works on the second hover over my menu item. The first time it appears instantly, like no jQuery is applied at all the first time around.

$(document).ready( function() {

// animate dropdown menus
$('#wp-admin-bar ul li').hover(
    function () {
        //show submenu
        $('ul', this).slideDown(180);
    }, 
    function () {
        //hide submenu
        $('ul', this).slideUp(180);
    }
);

});

The weird thing is if I add

$(this).addClass("hover");

The class is added immediately - on the the first hover.

I'm a little baffled by this.

A: 

Ok where does: $(this).addClass("hover"); come into the equation? Because it sounds like what is happening is that the first mouseIn is showing the div via CSS and then its ok from ther eon out with the jQuery code. Animations that hide and show dont work unless display is set with the style attribute of the element.

prodigitalson
You're right. The child `<ul>` position was off screen and moved on hover. Therefore did not have a `display` value in CSS.So I removed the `left: -999em` and set `display: none` in CSS. Then added `$('#nav ul li ul').css('display','block').slideUp(0);` to the jQuery. Then the menu also works if javascript is off.Here's a stripped down version if anyone wants to see it. http://www.deadlyhifi.com/experiment/01_hovermenu.php
deadlyhifi