2013-12-18 24 views
-1

我有一塊jquery,它在同一類的幾個div中褪色,有點像新聞提要。關閉使用jquery分開的同一類的每個div?

<script> 
$('.dashboard_notification').hide(); // this or use css to hide the div 
$(document).ready(function(){ 
    var time = 1000; 
    $('.dashboard_notification').each(function() { 
     $(this).delay(time).fadeIn(1000); 
     time += 1000; 
    }); 
}); 
</script> 
現在

,而不必到div類更改爲我所試圖做的是隔離這些(PREF的每一個:例如<div class="dashboard_notification">使用此代碼消失在多次一前一後有一個延遲像"dashboard_notification1/2/3/4"),使用戶可以通過點擊單獨關閉每個新聞源別人使用特殊的關閉按鈕的div我已經指派"dashboard_notification_close"

能有人告訴我我怎麼能做到這一點感謝,繼承人使用的代碼IM關閉div,但這只是關閉所有的新聞源,因爲它們都共享相同的div class =「dashboard_notification」

<script> 
$('.dashboard_notification_close').click(function(e) { //button click class name is myDiv 
    e.stopPropagation(); 
}) 

$(function(){ 
    $('.dashboard_notification_close').click(function(){ 
    $('.dashboard_notification').delay(100).fadeOut(500); 

}); 

}); 
</script> 
+2

後有關HTML標記,所以我們可以看到關係關閉按鈕和div之間。也許使用'$(本).closest( 'dashboard_notification ')',但只是我只是猜測...... –

回答

2

假設標記看起來是這樣的:

<div class="dashboard_notification"> 
... 
    <div class="dashboard_notification_close"></div> 
... 
</div> 

您可以使用this指點擊的按鈕,closest達到其外div

$('.dashboard_notification_close').click(function(){ 
    $(this).closest('.dashboard_notification').delay(100).fadeOut(500); 
}); 
0

內,您的點擊功能,切換到$('.dashboard_notification')$(this),它只會被點擊的元素上觸發,並不是所有的匹配選擇查詢。

+0

但'this'是'' .dashboard_notification_close''不是相對'' .dashboard_notification'' –

+0

問題我有,如果用戶點擊'dashboard_notification'這是假設超鏈接到該新聞提要的網址,所以,而不是讓他們點擊dashboard_notification關閉它,我想用'dashboard_notificaiton_close'觸發該個人的關閉'dashboard_notification' – user3080996

+0

然後,Andrei的解決方案將效果最佳。 –

相關問題