jquery - Showing submenu on mouseenter but disappears on hover -


couldn't think of more appropriate title, you're more welcome change it.

i have fixed left column navigation. when user hovers on 1 of navigation items in column, want show sub-menu right of column. problem when user moves cursor on new sub-menu element disappears.

this i'm @ far not sure of best way resolve this.

my project's fiddle

if hover on 1 of navigation items more 1750 milliseconds, you'll see sub-menu appear - if hover on disappears! how stay there? it's if need cancel mouseleave function when hovering sub-menu... not sure to...

my css code:

.page-wrapper {     width:100%;     height:100%; } .nav {     position:fixed;     height:100%;     left:0;     top:0;     width:175px;     background:#111;     padding:20px 0; } .nav-item {     height:40px;     line-height:40px;     padding:0 20px;     color:#fff;     font-size:13px;     cursor:pointer; } .nav-item:hover {     background:#222; } .submenu {     display:none;     position:fixed;     left:175px;     top:0;     width:175px;     height:100%;     background:#999; } 

my jquery code:

var sub_menu_timer; $('.nav-item').on({     mouseenter:function() {         sub_menu_timer = settimeout(function() {             $('.submenu').show();         },1750)     },     mouseleave:function() {         cleartimeout(sub_menu_timer);         $('.submenu').hide();     } }) 

my html code:

<div class="page-wrapper">     <div class="submenu"></div>     <div class="nav">         <div class="nav-item">             item 1         </div>         <div class="nav-item">             item 2         </div>         <div class="nav-item">             item 3         </div>     </div> </div> 

all need simple

$('.nav-item, .submenu').on({     mouseenter: function () {         $('.submenu').show();     },     mouseleave: function () {         $('.submenu').hide();     } }); 

see demo


update:

if want keep timeout then, need define functions separately -

var sub_menu_timer; $('.nav-item').on({     mouseenter: function () {         sub_menu_timer = settimeout(function () {             $('.submenu').show();         }, 1750)     },     mouseleave: function () {         cleartimeout(sub_menu_timer);         $('.submenu').hide();     } });   $('.submenu').on({     mouseenter: function () {         $('.submenu').show();     },     mouseleave: function () {         $('.submenu').hide();     } }); 

like shown here, when move out of submenu nav-item, sub menu goes away , comes after timeout.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -