2011-12-18 16 views
7

Estoy intentando retrasar la adición de una clase usando jquery. Todo el código funciona bien, pero me gustaría retrasar el .addClass('hideText') hasta que se complete la función hover out ¿podría alguien mostrarme cómo hacer esto, por favor?jQuery Animation Delay Agregar una clase

Aquí está el código:

$(document).ready(function() { 

$('.listing div').addClass('hideText'); 

$('.listing div').hover(

function() { 
    $(this) 
    .stop(true) 
    .removeClass('hideText') 
    .animate(
     {top: '0'}, 
     {duration: 300, easing: 'linear', queue: false} 
    ) 
    }, 
    function() { 
     $(this) 
     .stop(true) 
     .animate(
      {top: '150px'}, 
      {duration: 300, easing: 'linear', queue: false} 
     ) 
     .addClass('hideText') 
    }); 

});

Respuesta

2

Coloque la línea .addClass() en una devolución de llamada:

$(document).ready(function() { 

$('.listing div').addClass('hideText'); 

$('.listing div').hover(

function() { 
    $(this) 
    .stop(true) 
    .removeClass('hideText') 
    .animate(
     {top: '0'}, 
     {duration: 300, easing: 'linear', queue: false} 
    ) 
    }, 
    function() { 
     $(this) 
     .stop(true) 
     .animate(
      {top: '150px'}, 
      {duration: 300, easing: 'linear', queue: false}, 
      function() { 
       $(this).addClass('hideText'); 
      } 
     ); 
    }); 
}); 
+1

Hola gracias por la ayuda, desafortunadamente eso no funcionó. El .listo div aún se anima bien arriba y abajo, y la clase .hideText se agrega y quita inicialmente pero no se agrega después de que se completa la animación. – Gareth

+0

Proporcione un enlace a un ejemplo. – Interrobang

0

¿Ha intentado hacer cola la función como esta?

function() { 
     $(this).stop(true).queue(function (next) { 
      .animate(
       {top: '150px'}, 
       {duration: 300, easing: 'linear', queue: false}, 
      next(); 
     }) 
     function() { 
      $(this).addClass('hideText'); 
     } 
    }); 
+0

Hola Keith. Lo siento, fue hace tanto tiempo que olvidé cómo lo resolví. Gracias por tomarse el tiempo para responder sin embargo. – Gareth