【问题标题】:Bootstrap scroll table break when fix head修复头时引导滚动表中断
【发布时间】:2019-07-11 09:27:13
【问题描述】:

我想在滚动时修复表格标题。并且页面的其余内容滚动。但桌子的原始布局打破了。表格列和行的宽度大小不同。我无法解决这个问题。

我的代码:

HTML

<section class="scrollable padder">
<table class="table table-striped m-b-none text-sm m-t">
<thead class="ff">
<tr>
    <th >1col</th>
    <th >2col</th>
</tr>
</thead>
<tbody>
    <tr>
        <td class="new_td">field1</td>
        <td class="new_td">field2</td>
    </td>
</tbody>
</table>
</section>

JS

    $(".padder").scroll(function() {
    if ($(".padder").scrollTop() > 100) {
             $('.ff').addClass('fixed');
            }
            else
    {
     $('.ff').removeClass('fixed');
     }
    });  

CSS

.fixed{    
    position:fixed;
    top:50px;   
} 

【问题讨论】:

标签: javascript jquery html css twitter-bootstrap-3


【解决方案1】:

试试这个标签,让我知道结果

<section class="scrollable padder">
    <table class="table table-striped m-b-none text-sm m-t">
    <thead class="ff">
    <tr>
        <th >1col</th>
        <th >2col</th>
    </tr>
    </thead>
    <tbody>
        <tr>
            <td class="new_td">field1</td>
            <td class="new_td">field2</td>
        </tr>
    </tbody>
    </table>
    </section>

【讨论】:

    【解决方案2】:

    你可以使用这个来实现:

    <table id="fixed"></table>
    

    CSS

    #fixed {
    position: fixed;
    top: 0px; display:none;
    background-color:white;
    }   
    

    Js

    var $fix= $(".table > thead").clone();
    var $hfxd = $("#fixed").append($fix);
    $(".padder").scroll(function() {
    if ($(".padder").scrollTop() > 100 && $fix.is(":hidden")) 
    {
       $hfxd.show();
     }
     else
     {
     $hfxd.hide();
     }
    });  
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-06
      • 2016-10-26
      • 1970-01-01
      • 2020-05-16
      • 2019-05-02
      • 1970-01-01
      • 1970-01-01
      • 2018-05-23
      相关资源
      最近更新 更多