后,我有一个表有垂直滚动条化妆位置固定航向甚至滚动
<div id="div_data" style="top: 7px;">
<table id="data" cellspacing="0" cellpadding="0">
<thead>
<tr class="fix"><td class="newClass"> <div> Algebra </div></td>
<td class="newClass"><div> Geometry</div></td>
<td class="newClass"><div> Theorems</div></td>
<td class="newClass"><div> Comment</div></td>
</tr>
</thead>
<tbody style="overflow:auto; height:100px;">
......................
</tbody>
</table>
<table id="header-fixed" cellspacing="0" cellpadding="0"></table>
</div>
当我滚动#data table
,我需要做的表格标题元素是固定不scrolling.For那我已经做了以下的jquery代码:
var tableOffset = $("#data").offset().top;
var $header = $("#data > thead").clone();
var $fixedHeader = $("#header-fixed").append($header);
$("#div_data").scroll(function(){
$('#div_row_headers').scrollTop($('#div_data').scrollTop());
var offset = $(this).scrollTop();
if (offset >= tableOffset && $fixedHeader.is(":hidden")) {
$fixedHeader.show();
}
else if (offset < tableOffset) {
$fixedHeader.hide();
}
});
第一表的元素中的内容被克隆第二表内,但#header-fixed
台的位置是未在所述第一table.It的标题区域来到桌子中间。我只是想塞给它在 #data table
。我的CSS元素的位置如下:
#header-fixed {
position: fixed;
display:none;
background-color:white;
}
table#header-fixed tr td {
width: 155px;
}
table#header-fixed tr td div {
width: 155px;
float: left;
text-align: center;
}
编辑:当我滚动窗口滚动条,新表是固定的,我需要滚动表格,当我滚动窗口滚动条时
我用过的最简单的解决方案。 http://www.fixedheadertable.com/ – Binary101010 2014-10-20 10:40:33
@ Binary101010谢谢,我需要它那样的插件,但没有插件,我可以吗??我不想插件 – Techy 2014-10-20 10:42:38
对不起。我不知道我会如何自己写。我建议使用轻量级的插件,除非你真的需要重新发明轮子。 – Binary101010 2014-10-20 10:43:40