繁体   English   中英

使用JS滚动时设置固定的表头

[英]To set table headers fixed while scrolling using JS

在资源管理器中,使用css表达式滚动时,我可以保持表的thead部分固定。 以下是执行此操作的CSS代码段:

.standardTable thead tr {
position: relative;
top: expression(offsetParent.scrollTop);
}

但是,由于chrome不赞成使用表达式,因此这在chrome中不起作用。 我需要使用javascript或jquery更改上述类的“ top”属性的帮助。

是否可以使用javascript或jquery更改上述CSS中的top属性。

我已经看过很多例子,但是似乎没有一个例子做得很好。

(PS:我正在寻找一行代码来更改上面代码的top属性)

能做到吗

.standardTable thead tr {
    position:fixed;
    background-color: #fff;
}

此处的示例: http : //jsfiddle.net/hweb/4wZAU/

<style>
#ministres thead {
    display:block;
}
#ministres tbody {
    display:block;
    height:5em; /* 5 times the equivalent of a text "size". */
    overflow-y:scroll;
}

    #ministres thead tr th:nth-child(1) { /* column 1 ! */
        width:5em;
    }
    #ministres thead tr th:nth-child(2) { /* column 2 */
        width:10em;
    }
    #ministres tbody tr:first-child td:nth-child(1) { /* column 1 ! */
        width:5em;
    }
    #ministres tbody tr:first-child td:nth-child(2) { /* column 2 */
        width:10em;
    }
</style>
<table id="ministres" border="1">
    <thead>
        <tr><th>Nom</th><th>Ministère</th></tr>
    </thead>
    <tbody>
        <tr><td>JM Ayrault</td><td>Premier</td></tr>
        <tr><td>L Fabius</td><td>A. Etrangères</td></tr>
        <tr><td>V Peillon</td><td>Education</td></tr>
        <tr><td>C Taubira</td><td>Justice</td></tr>
        <tr><td>P Moscovici</td><td>Economie</td></tr>
        <tr><td>M Valls</td><td>Intérieur</td></tr>
    </tbody>
</table>

此处的示例: http : //jsfiddle.net/hweb/7eGT9/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM