The following jQuery code swaps table rows when some buttons are clicked. I would like to know how to add a transition effect so that there's a fade-in or fade-out transition effect when a row is moved (instead of the change happening instantaneously). I'm not sure where or how to apply the transition!
// 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
e开发者_StackOverflow社区lse 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()); }
In jQuery you can chain actions together... look here for a tut on chaining in 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(); }
Use .fadeOut() and .fadeIn() like so:
// 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'); }
});
精彩评论