2010-10-25 13 views
5

cuando hago clic en #button, se sigue haciendo el 'do something', aunque .wrapper está animándose y .wrapper span no está visible. entonces no está siguiendo las reglas ¿Qué pasa?jquery: this.not (': animated') && that.is (': visible') que no sigue las reglas, ¿problema de sintaxis? solo unas pocas líneas de código

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

'no (': animada')' no es un cheque, pero es un selector. por lo que devolverá '[]' si todos los ''.wrapper'' están animados – glebm

Respuesta

4

Aquí tienes una working demo:

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

Esto es un poco más limpio y sin las sentencias if. working demo

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

Cuestiones relacionadas