if ((scrollTop > offset.top) && (scrollTop < offset.top + $this.height()-base.$clonedHeader.height())) {
This can be achieved with div tables.
.td.header {
position: sticky;
top:0px;
}
查看这个jsfiddle,它提供了一个简单的例子。
编辑:
直觉告诉我们需要添加
Original Answer翻译成"最初的回答"
position: sticky;
一次加到表格行并不起作用。必须将其添加到每个要成为标题单元格的表格单元格中,这样就可以解决问题。
Original Answer翻译成:最初的回答
base.updateWidth = function () {
// Copy cell widths and classes from original header
$('th', base.$clonedHeader).each(function (index) {
var $this = $(this);
var $origCell = $('th', base.$originalHeader).eq(index);
this.className = $origCell.attr('class') || '';
//$this.css('width', $origCell.width());
});
// Copy row width from whole table
//base.$clonedHeader.css('width', base.$originalHeader.width());
};
// Run initializer
base.init();
// Set cell widths for header cells based on first row's cells
var firstTr = $this.children("tbody").children("tr").first();
var iCol = 0;
$(firstTr).children("td:visible").each(function()
{
var colWidth = $(this).outerWidth();
console.log(colWidth.toString());
var headerCell = $this.children("thead.tableFloatingHeader").children("tr").children("th:eq(" + iCol + ")");
var firstRowCell = $this.children("tbody").children("tr:first").children("td:eq(" + iCol + ")");
$(headerCell).outerWidth(colWidth);
$(firstRowCell).outerWidth(colWidth);
iCol++;
});