简体   繁体   中英

Jquery rollover but not the same child?

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');
});

});

////////////////////////////////////////////////
$(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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM