jQuery Hover Menu - When hovering over child - menu disappears

前端 未结 1 1687
刺人心
刺人心 2020-12-21 12:49

So I created a simple little hover, that uses a class from a link to show a div underneath.

The show/hide works fine, but I can\'t figure out how to set it so that i

1条回答
  •  攒了一身酷
    2020-12-21 13:13

    You can use clearTimeout(postTimer1) to stop the timer from executing. So if the user hovers over #dropdown1, clear the timer.

    Maybe something like this:

    $(document).ready(function() {
      var hideTimer = null
      var dropdown = $("#dropdown1", this)
      var menu = $(".menu-level-one", this)
    
      dropdown.hide();
    
      $([dropdown[0], menu[0]]).hover(
        function() {
          if (hideDropdownTimer)
            clearTimeout(hideDropdownTimer);
    
          dropdown.show();
        },
        function() {
          if (hideDropdownTimer)
            clearTimeout(hideDropdownTimer);
    
          hideDropdownTimer = setTimeout(function() {
            dropdown.hide()
          }, 300)
        }
      )
    })
    

    0 讨论(0)
提交回复
热议问题