Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove row from table with fadeOut effect

I have a table that has some rows,each row has a background. There is a button that remove specified row with jQuery fadeOut, but during the operation the design doesn't good.cells background will be white.

$(document).ready(function(){
    $(".btn").click(function(){
        $("#row").fadeOut();
    });
});

This jsfiddle describes my problem better.

like image 928
Saman Gholami Avatar asked Sep 02 '13 10:09

Saman Gholami


1 Answers

The below code will achieve a shrinking row and then hide it without turning the background white

$(document).ready(function(){
    $(".btn").click(function(){
        $("#row td").animate({'line-height':0},1000).hide(1);
    });
});

Fiddle example

Animating line height doesnt go all that smoothly with webkit however.

You can also animate the hide() function by setting its parameter to the time taken to hide

$(document).ready(function(){
    $(".btn").click(function(){
        $("#row").hide(1000);
    });
});

That however also suffers from the "white background problem" since it animates the opacity.

Adapting from http://blog.slaks.net/2010/12/animating-table-rows-with-jquery.html/ gives a nice shrinking without white space in at least Chrome and Firefox

Fiddle

$(document).ready(function () {
    $(".btn").click(function () {
        $('#row')
            .children('td, th')
            .animate({
            padding: 0
        })
            .wrapInner('<div />')
            .children()
            .slideUp(function () {
            $(this).closest('tr').remove();
        });
    });
});
like image 178
DGS Avatar answered Sep 20 '22 09:09

DGS