javascript - 如何在页面滚动时保持克隆的表头不变

标签 javascript jquery html css

我的 Pastebin:http://pastebin.com/pUstKXJz

当您滚动超过 100 像素时,会出现一个警告,并且还会显示克隆的标题。我如何修改 JQuery,以便在我向下滚动时克隆​​的 header 粘在页面顶部。

它目前已被注释掉,因为它不起作用。

请帮我解决这个问题。

这是图片:

enter image description here

输出是基于下面列出的答案:

enter image description here

enter image description here

最佳答案

您必须移动 <tr class="showOnlyAfterScroll">..</tr>在当前表之外并将其包装在实际 <table class="tblPrint">..</table> 之前的另一个表中,并且您还必须将“showOnlyAfterScroll”类设置为新的 <table>标签而不是 <tr> ,像这样:

<!--your new table-->
<table class="tblPrint showOnlyAfterScroll">
    <tbody>
        <tr class="mainTR">...</tr>
    </tbody>
</table>

<!--your current table-->
<table class="tblPrint">
    <tbody>...etc

现在添加以下 css:

.showOnlyAfterScroll{
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
}

最后,您必须调整所有五列的宽度百分比,使它们在两个表中相同:

.mainTR > th:nth-child(1){ width: 15%; }
.mainTR > th:nth-child(2){ width: 15%; }
.mainTR > th:nth-child(3){ width: 20%; }
.mainTR > th:nth-child(4){ width: 30%; }
.mainTR > th:nth-child(5){ width: 20%; }

但要确保列的总宽度为 100%。

希望这对您有所帮助!

关于javascript - 如何在页面滚动时保持克隆的表头不变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28521244/

相关文章:

html - 此 URL 如何响应图像或嵌入该图像的网页?

javascript - vuejs使用fetch Api获取projects.json : Unexpected token < in JSON at position 0的数据

javascript - 从 JQuery UI 对话框提交 MVC 部分页面

javascript - 未捕获的语法错误 : Unexpected token ILLEGAL on Toggle

jQuery 模板 - 渲染通用 json 对象

javascript - 添加类时单击时停止 jquery 循环函数

html - 如何让<table></table>均匀显示不同的item?

javascript - 动态创建 Angular View

javascript - Highcharts 显示标签不正确的数据点

javascript - 如何从 ListView 打开新 View