2016-05-13 4 views
0

私の英語のために申し訳ありません!スクロールするときにテーブルヘッダーを修正したいそして、残りのページコンテンツをスクロールします。しかし、テーブルの元のレイアウトが壊れます。テーブルの列と行の幅は異なるサイズです。私はそれを修正することはできません。よろしく。修正頭の時のブートストラップスクロールテーブルブレーク

マイコード:

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; 
} 
+0

固定して[ブートストラップ4台の –

+0

が重複する可能性いくつかのタグ閉鎖問題になることがありヘッダーとスクロールテーブルの本体ではスクロールできません](https://stackoverflow.com/qu estots/42483320/bootstrap-4-table-fixed-header-and-scrolling-table-body-doesnt-let-tbody-s) –

答えて

0

このタグを試してみて、私は結果をお知らせ

<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> 
+0

申し訳ありません:)コードには

というタグがあります – gamernnov

0

あなたはこれを使用して実装できます

<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(); 
} 
}); 
関連する問題