2013-03-19 156 views
0
$('#navigation li.parent').mouseover(function() { 
    $('#news-ticker').hide(); 
    $('ul.child', this).slideDown(); 
}); 
$('#navigation .child').mouseleave(function() { 
    setTimeout(function(){ 
     $(this).hide(); 
     $('#news-ticker').slideDown(); 
    },2000); 
}); 

...幾乎可以工作,只是一個問題,我該如何隱藏subnav兄弟姐妹?如果我這樣做$('ul.child', this).slideDown().siblings().hide();它隱藏了整個家長。隱藏的兄弟姐妹

+4

什麼是HTML的樣子? – rampion 2013-03-19 10:53:01

+0

請在jsfiddle中發佈您的代碼。 – 2013-03-19 10:58:07

回答

0

嘗試:

$('#navigation li.parent').mouseover(function() { 
    $('#news-ticker').hide(); 
    $(this).parent().find("ul.child").not($('ul.child', this)).hide(); 
    $('ul.child', this).slideDown(); 
}); 
$('#navigation .child').mouseleave(function (e) { 
    setTimeout(function(){ 
     $(this).hide(); 
     $('#news-ticker').slideDown(); 
    },2000); 
    e.stopPropagation(); 
}); 
+0

on'mouseleave'子菜單不會隱藏,但newsticker會顯示在它上面 – 3zzy 2013-03-19 12:18:22

0

只需隱藏所有元素,然後再顯示要打開的元素。

$('ul.child', this).hide(); 
$('ul.child', this).slideDown(); 
-1

在了slideDown方法,我認爲你可以給它雙參數,像這樣:

slideDown(500,function(){$(this).fadeOut(500,function(){$(this).hide();});}); 

首先是時間間隔,第二個是一個回調函數。一次函數調用完成。 但隨着你的代碼,我建議使用hover方法:

$('#navigation li.parent').hover(function(){ 
    //on mouse enter 
    $('#news-ticker').hide(); 
    $('.child', this).slideDown(500); 
},function(){ 
    //on mouse leave 
    $('#new-ticker').slideDown(500,function(){$('.child',this).hide();}); 
}); 

小很難說什麼,我想是這樣做沒有HTML。抱歉。