How to Use slideDown (or show) function on a table row?

后端 未结 21 2735
清歌不尽
清歌不尽 2020-11-22 09:03

I\'m trying to add a row to a table and have that row slide into view, however the slidedown function seems to be adding a display:block style to the table row which messes

21条回答
  •  梦谈多话
    2020-11-22 09:44

    I did use the ideas provided here and faced some problems. I fixed them all and have a smooth one-liner I'd like to share.

    $('#row_to_slideup').find('> td').css({'height':'0px'}).wrapInner('
    ').parent().find('td > div').slideUp('slow', function() {$(this).parent().parent().remove();});

    It uses css on the td element. It reduces the height to 0px. That way only the height of the content of the newly created div-wrapper inside of each td element matters.

    The slideUp is on slow. If you make it even slower you might realize some glitch. A small jump at the beginning. This is because of the mentioned css setting. But without those settings the row would not decrease in height. Only its content would.

    At the end the tr element gets removed.

    The whole line only contains JQuery and no native Javascript.

    Hope it helps.

    Here is an example code:

        
                
                        
                
                
                        
    header_column 1 header column 2
    row 1 leftrow 1 right
    row 2 leftrow 2 right
    row 3 leftrow 3 right
    row 4 leftrow 4 right

提交回复
热议问题