jQuery slideToggle on a table with thead and tbody elements. No animation.

后端 未结 2 1347
慢半拍i
慢半拍i 2020-12-09 17:22

I have a table with a thead and tbody sections. I have applied a slideToggle on this successfully, but the animation is broken.

When a user clicks on the thead, I wa

相关标签:
2条回答
  • 2020-12-09 18:09

    It disappears because <tbody> normally will get no shorter than the tallest td, no matter what you set its height to with CSS.

    This is why the natural-height tbody just seems to disappear, while the one with artificial extra-height appears to run until the tr reached its natural height.

    You can kludge around this with tbody {display:block;}. See the kludge at jsFiddle.

    But, notice the effect that has when a table height is set.

    Probably, the best way is to wrap the whole table in a div and slideToggle that, like so:

    <table class="AbbyNormal">
        <thead><tr><td colspan="3">TABLE HEADING</td></tr></thead>
    </table>
    <div class="tableWrap">
        <table class="AbbyNormal">
          <tbody>
            <tr>
                <td class="first" colspan="1">Cell Contents</td>
                <td colspan="1">Cell Contents</td>
                <td colspan="1">Cell Contents</td>
            </tr>
          </tbody>
        </table>
    </div>
    

    Just be sure and fix the table widths the same.

    See it in action at jsFiddle.

    0 讨论(0)
  • 2020-12-09 18:19

    I think you should set an height to the tbody to make it work, look at this fiddle: http://jsfiddle.net/nicolapeluchetti/AsDvb/

    css:

    tbody{
    
        height: 1000px;
        background-color: yellow;
    }
    
    0 讨论(0)
提交回复
热议问题