table表头固定
方式一
<style>
table tbody {
display:block;
height: 600px;
overflow-y:auto;
overflow-x: hidden;
}
table thead, tbody tr {
display:table;
width:100%;
table-layout:fixed;
}
table thead {
width: calc( 100% - 1em )
}
</style>
方式二
<div id="table-cont" style="overflow-y: auto;">
<table>
<thead>
<tr>
<th>名称</th>
<th>类型</th>
<th>大小</th>
<th>最后修改时间</th>
<th>操作</th>
</tr>
</thead>
<tbody id="privateDir_table"></tbody>
</table>
</div>
window.onload = function () {
$("#table-cont").css("height", $(document.body).height() - 120);
var tableCont = document.querySelector('#table-cont')
function scrollHandle(e) {
var scrollTop = this.scrollTop;
this.querySelector('thead').style.transform = 'translateY(' + scrollTop + 'px)';
}
tableCont.addEventListener('scroll', scrollHandle)
}