Click here to Skip to main content
14,868,503 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello people,
i built this dropdown menu, i want to stop slideUp when i hover the sub list, likes any dropdown menu, to chose/click something in sub menu.
how can i do it plz ?

JavaScript
$(function(){
    $(".sub").hide();
    $("#btnHomeLi").mouseenter(function () {
        $(".sub").slideDown('slow');
    });
    $("#btnHomeLi").mouseleave(function () {
        $(".sub").slideUp('slow');
    });

});


HTML
<ul class="ulButtons" id="btnHome">
          <li>
              <button class="btn" id="btnHomeLi">Home</button>
              <button class="btn">Categories</button>
              <button class="btn">About Us</button>
              <button class="btn">Contact</button>
          </li>
          <li>
              <ul class="sub">
                  <li class ="liSubDisplay"> <a href=" #">Consulting Services</a></li>
                  <li class="liSubDisplay"> <a href="#">Investment</a></li>
                  <li class="liSubDisplay"> <a href="#">Property Management</a></li>
                  <li class="liSubDisplay"> <a href="#">Development</a></li>
              </ul>
          </li>
      </ul>
Posted

1 solution

Update your script as follows :

XML
<script type="text/javascript">
        $(function () {
            $(".sub").hide();
            $("#btnHomeLi").mouseenter(function () {
                $(".sub").slideDown('slow');
            });
            $("#btnHomeLi").mouseleave(function () {
                $(".sub").slideUp('slow');
            });
            $('.sub').hover(function () { $(this).stop(); }, function () { $(this).slideUp('slow'); });
            });
    </script>
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900