2010-10-25 7 views
5

quando faccio clic su #button, sta facendo il 'do something', anche se .wrapper è in animazione e .wrapper span non è visibile. quindi non sta seguendo le regole. Cosa c'è che non va?jquery: this.not (': animated') && that.is (': visible') non segue le regole, problema di sintassi? solo poche righe di codice

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

'non (': animato')' non è un assegno, ma è un selettore. quindi restituirà '[]' se tutti ''.wrapper''s sono animati – glebm

risposta

4

Qui avete un working demo:

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

Questo è un po 'più pulito, senza istruzioni if. working demo

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

Problemi correlati