Search code examples
jquerycssjquery-hoveranimate.cssmegamenu

Why isn't .hover() working with Animate.css?


I'm creating a mega menu. Everything is working great except when the mouse hovers over the menu itself -- after it appears with the animation -- the menu then hides.

This only happens when the animate.css classes "animated" and "bounceIn" are in the code. When they're removed, and just the class "show" is added, the menu doesn't hide when it's hovered and works correctly.

Is there a special twist to using animate.css with .hover()?

HTML

<div class="nav">
    <ul>
        <li class="wsite-nav-1">Home</li>
    </ul>
    <div class="mega-menu">
          <div class="menu-1 menu">Mega Menu</div>
    </div>
</div>

CSS

.menu {
  border:1px solid #004698;
  padding:2em;
  box-sizing:border-box;
  display:none;
}
.menu.show {
  display:block;
}

jQuery

  // Mega Menu
  $('.menu-1, .wsite-nav-1').hover(function() {
    $('.menu-1.menu').addClass('show animated bounceIn');
  },function() {
    $('.menu-1.menu').removeClass('show animated bounceIn');
  });

Solution

  • You can use only css as below and move .mega-menu inside li

    .menu {
      border:1px solid #004698;
      padding:2em;
      box-sizing:border-box;
      display:none;
    }
    
    .wsite-nav-1:hover .menu{
        display:block;
        -webkit-animation: bounceIn 1s;
        animation: bounceIn 1s;
    }
     <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.7.0/animate.css">
    <div class="nav">
        <ul>
            <li class="wsite-nav-1">Home
              <div class="mega-menu">
                <div class="menu-1 menu">Mega Menu</div>
              </div>
            </li>
        </ul>
    </div>