Jquery rollover but not the same child?

37 views Asked by At

What I want to do is when I rollover .mainmenu then the .submenu fade in, but the problem is that both of them are not parent and child related, so how can I make the .submenu remain visible when I move my cursor from .mainmenu to .submenu?

http://codepen.io/vincentccw/pen/LnvJE

my html:
//////////////////////////////////////////////

<div class="mainmenu">this is text</div>
<div class="submenu">this is text2</div>

//////////////////////////////////////////////

my js:
//////////////////////////////////////////////

$( document ).ready(function() {  

$(".mainmenu, .submenu").mouseenter(function(){
    $(".submenu").stop(true,true).slideToggle();
    console.log('slide down');
}).mouseleave(function(){
    $(".submenu").stop(true,true).slideToggle();
    console.log('slide up');
});

});

////////////////////////////////////////////////
1

There are 1 answers

0
AudioBubble On
$(document).ready(function () {

$(".mainmenu").mouseenter(function () {
    $(".submenu").stop(true, true).slideToggle();
    // console.log('slide down');
}).mouseleave(function (e) {
    if (e.relatedTarget.className != "submenu") $(".submenu").stop(true, true).slideToggle();
    //  console.log('slide up');
});

$(".submenu").mouseleave(function (e) {
    $(".submenu").stop(true, true).slideToggle();
    //  console.log('slide up');
});

});

http://jsfiddle.net/3bLbJ/1/