2012-11-30 68 views
2

我試圖與IE兼容的菜單... :(顯示孩子的onmouseover但移開鼠標隱藏孩子

我使用具有這種結構的CSS做了一個菜單:

<div id="menu"> 
<ul id="menuu"> 
<li><a href="#" class="parent">Parent</a> 
<ul class="children"> 
<li><a href="/#">name</a></li> 
<li><a href="/#">name</a></li> 
<li><a href="/#">name</a></li> 
</ul> 
</li> 
</ul> 
</div> 

我想要做的是:
- 當鼠標懸停a.parent節目的兒童在使用淡入
- 當你從父母都不亮,並且也出了兒童,孩子們隱瞞
- 當你在另一個孩子去掩蓋前一個。子女。

我做了一個腳本,但我無法以正確的方式隱藏孩子。

<script> 
$('a.parent').hover(function() { 
    if($(this).next().hasClass('children')){ 
     $(this).next().fadeIn(); 
    }else{ 
     //alert('false'); 
    } 
}, 
function() { 
//here when you are out from a.parent 

}); 
</script> 

因爲如果我隱藏的孩子(子)時,我從父不幹了,我無法打開任何兒童的鏈接,因爲當我從父母到孩子動,孩子是隱伏.. 所以我不知道如何解決它... :(

有人能幫助我嗎? 非常感謝你!

+0

它在其他瀏覽器中工作嗎? – user1167442

回答

0

如何與背景交融的對象,而不是使之消失?

0

這應該工作:

$('a.parent').bind('mouseover',function(){ 
    $(this).addClass('hover'); 
    if($(this).next('ul').hasClass('children')){ 
     $(this).next('.children').addClass('expanded');   
    $(this).next('.children').stop().fadeIn(); 
    } else { 
    // 
    } 
}).bind('mouseout',function(){ 
    $(this).removeClass('hover'); 
    if($(this).next('.children').not('.expanded')) 
     { 
     //If need be, you can add a delay here to make sure the mouse made it to 'children' 
     $('.children').stop().fadeOut(); 
     } 
}) 

$('.expanded').bind('mouseout',function(){ 
    $(this).removeClass('expanded'); 
    if($(this).prev('a').not('.hover')){ 
     $(this).stop().fadeOut(); 
    } 
}) 
+0

另外 - 其他人可能會不同意我這裏 - 我認爲這是一個很好的做法,以避免空$(elem).next()語句,因爲代碼可能會令人困惑。除非有一個原因(比如選擇器不知道或者不明確),否則我總是把你正在尋找的選擇器的名稱作爲$(elem).next()的參數,例如, $(本)。接下來( '孩子')。 – user1167442

+0

嗯不工作孩子仍然總是可見.. – peterpeterson

+0

再試一次 - 修訂。 – user1167442