2012-12-11 28 views
2

我擁有帶觸發器和疊加層的塊。帶重疊淡入/淡出觸發器的多個按鈕

下面是一個例子的jsfiddle:http://jsfiddle.net/uRstt/7/

當疊加淡入淡出效果觸發特定塊我想在其他區塊覆蓋淡出上。同樣,如果您在具有活動疊加層的塊上單擊觸發器,則它必須淡出。

這是我試圖取得成功的代碼。

$(".trigger").click(function(){ 
    !$(this).parent().find(".overlay").fadeOut(); 
    $(this).parent().find(".overlay").stop(true,true).fadeToggle(); 
}); 

下面是正確的代碼感謝Adeneo

$(".trigger").click(function(){ 
    $(this).siblings(".overlay").stop(true,true).fadeToggle().closest('.container').siblings().find('.overlay').fadeOut(); 
}); 

這裏的工作jsFiddle

+1

這樣[** ** FIDDLE(http://jsfiddle.net/uRstt/8/)? ?? – adeneo

+0

完美。非常感謝。 – 404notfound

回答

0

一個例子做到這一點:

$(".trigger").click(function(){ 
    $(this).siblings(".overlay").stop(true,true).fadeToggle() 
    .closest('.container').siblings().find('.overlay').fadeOut(); 
}); 
+0

這不能正常工作。如果你點擊觸發按鈕淡出它,它什麼都不做。 Adeneo擁有完美的解決方案。檢查我的問題。它包含正確的解決方案。 – 404notfound

+0

@ 404notfound我知道這有點淘氣,但我改變了我的答案,只是爲了不導致錯誤,並讓你的問題得到正確的答案。 – ParPar

+0

哈哈正確答案越多越好,越好。 – 404notfound

0

如果我理解正確的話,這樣的事情應該工作:

$(".trigger").click(function(){ 
    $(this).next().stop(true,true).fadeToggle(); 
    $(this).parent().siblings().children('.overlay:visible').fadeOut(); 
}); 

演示:http://jsfiddle.net/uRstt/9/

+0

這適用於該示例,但出於某種原因,不適用於我的代碼。 Adeneo有一個與我的代碼一起工作的解決方案。謝謝 – 404notfound