2010-10-25 46 views
5

當我點擊#button時,它仍然在執行'do something',即使.wrapper正在動畫並且.wrapper span不可見。所以它不遵守規則。怎麼了?jquery:this.not(':animated')&& that.is(':visible')不遵循規則,語法問題?只有幾行代碼

$('#button').click(function(){ 
    if(
    $('.wrapper').not(':animated') && $('.wrapper span').is(':visible') 
) { 
    //do something 
    } 
}) 
+1

'未( ':動畫')'不是檢查,但是一個選擇器。所以如果所有''.wrapper''都是動畫的,它會返回'[]' – glebm 2010-10-25 06:22:29

回答

4

這裏有一個working demo

$('#button').click(function(){ 
if( $('.wrapper:animated').length>0) 
{ 
$(".wrapper").text("animating") ; 
} 
    if(
    $('.wrapper:animated').length<1) { 
$(".wrapper").text("not animating") ; 
    } 
}) 
6

這是一個有點清潔無if語句。 working demo

$('#button').click(function(){ 
    $('.wrapper').filter(':animated').text("animating..."); 
    $('.wrapper').filter(':not(:animated)').text("not animating..."); 
}) 

相關問題