开发者

jQuery slideDown / slideUp problem

i have a little issue with slideDown / slideUp. I have a menu with sub-menus inside, what i'm trying to acchieve is to display the submenu on the menu mouse over, and I'm doing it like this:

<script type="text/javascript">
$(document).ready(function(){
        $("#menu>li>ul").hide();
        $("ul#menu>li a").mouseover(function(){                     
            $(this).next("ul").slideDown('1000');
            $(this).next("ul").addClass("current_submenu");     
        });
        $(".submenu>li").click(function(){                          
            $(".current_submenu").slideUp('1000');          
        }); 
});
</script>
<ul id="menu">
             <li><a class="album" id="beauty-fashion" href="#">Beauty/Fashion</a>
                <ul>
                    <li><a href="#">Beauty 1</a></li>
                </ul>
             </li>             
             <li><a class="album" id="covers" href="#">Covers</a></li>
             <li><a class="album" id="editorial" href="#">Editorial</a></li>
             <li><a class="album" id="advertising" href="#">Advertis开发者_如何学运维ing</a></li>
             <li><a class="album" id="fx" href="#">FX</a></li>
             <li><a class="album" id="portraits" href="#">Portraits</a></li>
             <li><a class="album" id="taly" href="#">Taly</a></li>
             <li><a class="disabled" href="#" id="previousImage">Previous</a></li>
             <li><a href="#" id="toggleAnimation">Pause</a></li>
             <li><a class="disabled" href="#" id="nextImage">Next</a></li>
</ul>

The submenu slides down, but when i do the mouseout from it it wont slideUp again. ¿What I'm doing wrong?

Thanks so much for your help guys!


This javascript should work:

$(document).ready(function(){
    $("#menu>li>ul").hide();
    $("ul#menu>li").hover(function(){                     
        $(this).find("ul").slideDown(200).addClass("current_submenu");
    }, function(){
        $(this).find("ul").slideUp(200).removeClass("current_submenu");
    });
});

Take a look at http://api.jquery.com/hover/ to learn about how it is a shorthand for mouseenter and mouseleave.

I also noticed that your slideUp and slideDown time was inserted as a string. It should be an integer, or something like 'fast' or 'slow' for pre-defined times.


you could try this script:

$(document).ready(function(){
  $("#menu>li>ul").hide();
  $("#menu>li>ul>li").click(function(){
      $(this).slideUp(1000).removeClass("submenu");  
  });
  $("ul#menu>li").hover(function(){                     
      $(this).find("ul").slideDown(1000).addClass("submenu");
  });  
});


You need to bind a function to the mouseout event to close the menu.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜