2010-10-29 5 views
2

Le code jQuery suivant permute les rangées de la table lorsque certains boutons sont cliqués. Je voudrais savoir comment ajouter un effet de transition pour qu'il y ait un effet de transition de fondu entrant ou sortant quand une ligne est déplacée (au lieu que la modification se produise instantanément). Je ne suis pas sûr où et comment appliquer la transition!Comment ajouter des effets de transition aux lignes de table avec jQuery

// Move item to top or up/down by one 
$(".top,.up,.down").click(function(){ 

    // This row 
    var row = $(this).parents("tr:first"); 

    // When up is pressed 
    if ($(this).is(".up")) { row.insertBefore(row.prev()); } 

    // When top is pressed 
    else if ($(this).is(".top")) { var firstRow = row.parent().find("tr:first").not(row); row.insertBefore(firstRow); } 

    // When down is pressed 
    else { row.insertAfter(row.next()); } 

Répondre

2

Dans jQuery, vous pouvez les actions de la chaîne ensemble ... chercher here pour une Tut sur enchaînant dans jQuery

$(".top,.up,.down").click(function(){ 

     // This row 
     var row = $(this).parents("tr:first"); 

     // When up is pressed 
     if ($(this).is(".up")) { row.fadeOut().insertBefore(row.prev()).fadeIn(); } 

     // When top is pressed 
     else if ($(this).is(".top")) { 
        var firstRow = row.parent().find("tr:first").not(row); 
        row.fadeOut().insertBefore(firstRow).fadeIn(); 
       } 

     // When down is pressed 
     else { row.fadeOut().insertAfter(row.next()).fadeIn(); } 
+0

je le fadeout() .insertbefore(). fadein() enchaîne et l'animation s'est produite après le déplacement de ligne. Après avoir lu cette réponse http://stackoverflow.com/a/4369277/755404 Je l'ai résolu ... row.fadeOut ("lent", function() {row.insertAfter (row.next()). FadeIn ("lent"); }); – Darren

1

Utilisez .fadeOut() et .fadeIn() comme ceci:

// Move item to top or up/down by one 
$(".top,.up,.down").click(function(){ 

    // This row 
    var row = $(this).parents("tr:first"); 

    // When up is pressed 
    if ($(this).is(".up")) { row.fadeOut('slow'); row.insertBefore(row.prev()); row.fadeIn('slow'); } 

    // When top is pressed 
    else if ($(this).is(".top")) { var firstRow = row.parent().find("tr:first").not(row); row.fadeOut('slow'); row.insertBefore(firstRow); row.fadeIn('slow'); } 

    // When down is pressed 
    else { row.fadeOut('slow'); row.insertAfter(row.next()); row.fadeIn('slow'); } 
}); 
Questions connexes