javascript - JQuery - Mouseleave not working -


i have replicated problem here - jsfiddle.

on mouseleave, reverse animate effect disappears.

i think has "display" property, i'm not sure how resolve this. guess reason happens due "display:block" on hover, reverts display:none?

if force "display:block" on submenu element, shows submenu options @ once.

html

<nav>   <ul class="level-2">     <li class="has-child"> <a href="/clients/">clients</a>       <ul class="sublevel level-3 submenu">         <li class="nav-item"> <a href="/clients/test1/">test1</a> </li>       </ul>     </li>     <li class="has-child"> <a href="/services/">services</a>       <ul class="sublevel level-3 submenu">         <li class="nav-item"> <a href="/services/test2/">test2</a> </li>       </ul>     </li>   </ul> </nav> 

jquery

$(document).ready(function () {     $('.level-2 li').on({         mouseenter: function () {             $('.submenu').stop().animate({ 'margin-left':"300px" }, 1000);         },         mouseleave: function () {             $('.submenu').stop().animate({ 'margin-left':"-200px" }, 1000);         }     }); }); 

the problem display: none assigned .submenu rule, move cursor out of element display set none remove item being rendered.

$(document).ready(function() {    $('.level-2 > li').on({      mouseenter: function() {        $('.submenu', this).stop().removeclass('hidden').animate({          'margin-left': "300px"        }, 1000);      },      mouseleave: function() {        $('.submenu', this).stop().animate({          'margin-left': "-200px"        }, 1000);      }    });  });
nav ul li {    list-style: none;    color: #cccccc;  }  .hidden {    display: none;  }  .submenu {    position: fixed;    left: -120px;    top: 0;    width: 200px;    height: 100%;    background: #3a4247 none repeat scroll 0 0;    z-index: -1;    filter: alpha(opacity=80);    -moz-opacity: 0.8;    -khtml-opacity: 0.8;    opacity: 0.8;  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>  <nav>    <ul class="level-2">      <li class="has-child"> <a href="/clients/">clients</a>        <ul class="sublevel level-3 submenu">          <li class="nav-item"> <a href="/clients/test1/">test1</a> </li>        </ul>      </li>      <li class="has-child"> <a href="/services/">services</a>        <ul class="sublevel level-3 submenu">          <li class="nav-item"> <a href="/services/test2/">test2</a> </li>        </ul>      </li>    </ul>  </nav>


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -