您可以在表标记中使用add和tbody来转移标题和数据。比定义CSS适当对齐。之后,你可以使用下面的代码为粘头:
jsFiddle Example
的jQuery:
$(document).ready(function() {
var theadH = $('thead').outerHeight(true);
$(window).scroll(function() {
var scrollVal = $(this).scrollTop();
if (scrollVal > 0) {
$('thead').css({'position':'fixed'});
$('tbody').css({'margin-top': theadH +'px'});
} else {
$('thead').css({'position':'static'});
$('tbody').css({'margin-top': '0px'});
}
});
});
CSS:
table { width: 100%; }
th,td { width: 20%; } /* there are five collums */
thead { top:0; }
HTML:
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<thead>
<tr>
<th>ÜRÜN</th>
<th>ADEDİ</th>
<th>TUTAR</th>
<th>ÖDENEN TUTAR</th>
<th>MUALLAK TUTAR</th>
</tr>
</thead>
<tbody>
<tr>
<td>90 - Dask</td>
<td>2</td>
<td>133</td>
<td>2347630</td>
<td>2347630</td>
</tr>
<tr>
<td>95 - Dask</td>
<td>4</td>
<td>140</td>
<td>234699</td>
<td>234699</td>
</tr>
</tbody>
</table>
检查此答案:http://stackoverflow.com/a/11983369/1428241没有插件的使用 –
这个小提琴的问题是什么? http://jsfiddle.net/cePkr/1/ –
@PratikJoshi滚动时,标题不会浮动。 – MacMan