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

后端 未结 21 2141
清歌不尽
清歌不尽 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:46

    I had problems with all the other solutions offered but ended up doing this simple thing that is smooth as butter.

    Set up your HTML like so:

    
      
    
    

    Then set up your javascript like so:

    function toggleRow(rowid){
      var row = document.getElementById("row" + rowid)
    
      if(row.style.height == "0px"){
          $('#div' + rowid).slideDown('fast');
          row.style.height = "1px";   
      }else{
          $('#div' + rowid).slideUp('fast');
          row.style.height = "0px";   
      } 
    }
    

    Basically, make the "invisible" row 0px high, with a div inside.
    Use the animation on the div (not the row) and then set the row height to 1px.

    To hide the row again, use the opposite animation on the div and set the row height back to 0px.

提交回复
热议问题