<html style="width:100%;height:100%">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
</head>
<body style="width:100%;height:100%">
v1.1
<div style="width:100%;height:80%;overflow:scroll">
<table border="1" style="width: 200%; table-layout: fixed">
<thead>
<!--rowspan="2" colspan="2"-->
<tr height="200px" id="row1">
<th width="20%" class="firsttop firstColBG">
name1
</th>
<th width="20%" colspan="2" class="top titleBG">
name2
</th>
<th width="20%" colspan="2" class="top titleBG">
name4
</th>
</tr>
<tr height="200px" id="row2">
<th width="20%" class="first firstColBG">
name1
</th>
<th width="20%" class=" titleBG">
name2
</th>
<th width="20%" class=" titleBG">
name3
</th>
<th width="20%" class=" titleBG">
name4
</th><th width="20%" class=" titleBG">
name5
</th>
</tr>
</thead>
<tbody>
<tr height="100px">
<td class="first firstColBG">ok1</td><td>ok2</td><td>ok3</td><td>ok4</td><td>ok5</td>
</tr>
<tr height="100px">
<td class="first firstColBG">ok1</td><td>ok2</td><td>ok3</td><td>ok4</td><td>ok5</td>
</tr>
<tr height="100px">
<td class="first firstColBG">ok1</td><td>ok2</td><td>ok3</td><td>ok4</td><td>ok5</td>
</tr>
<tr height="100px">
<td class="first firstColBG">ok1</td><td>ok2</td><td>ok3</td><td>ok4</td><td>ok5</td>
</tr>
<tr height="100px">
<td class="first firstColBG">ok1</td><td>ok2</td><td>ok3</td><td>ok4</td><td>ok5</td>
</tr>
<tr height="100px">
<td class="first firstColBG">ok1</td><td>ok2</td><td>ok3</td><td>ok4</td><td>ok5</td>
</tr>
<tr height="100px">
<td class="first firstColBG">ok1</td><td>ok2</td><td>ok3</td><td>ok4</td><td>ok5</td>
</tr>
<tr height="100px">
<td class="first firstColBG">ok1</td><td>ok2</td><td>ok3</td><td>ok4</td><td>ok5</td>
</tr>
<tr height="100px">
<td class="first firstColBG">ok1</td><td>ok2</td><td>ok3</td><td>ok4</td><td>ok5</td>
</tr>
<tr height="100px">
<td class="first firstColBG">ok1</td><td>ok2</td><td>ok3</td><td>ok4</td><td>ok5</td>
</tr>
<tr height="100px">
<td class="first firstColBG">ok1</td><td>ok2</td><td>ok3</td><td>ok4</td><td>ok5</td>
</tr>
<tr height="100px">
<td class="first firstColBG">ok1</td><td>ok2</td><td>ok3</td><td>ok4</td><td>ok5</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
<style>
.firstColBG{
background-color:#368dbb
}
.titleBG{
background-color:#36bb38
}
.firsttop{
position: sticky;
position: -webkit-sticky;
left: 0;
top:0;
z-index: 200;
}
.first{
position: sticky;
position: -webkit-sticky;
left: 0;
z-index: 100;
}
.top{
position:sticky;
position: -webkit-sticky;
top:0; /* 第一列最上 */
z-index: 100;
}
</style>
<script>
var row2 = document.getElementById("row2");
console.log(row2.offsetTop );
var row2Top = row2.offsetTop;
var childrens = row2.children;
console.log(childrens.length);
for(var i = 0;i<childrens.length;i++){
var row2Td = childrens[i];
console.log(row2Td);
row2Td.style.position="sticky";
row2Td.style.top=row2Top;
if(i==0 ){
row2Td.style.zIndex = 200;
}else{
row2Td.style.zIndex = 100;
}
}
</script>
固定表头
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 表格设置table-layout:fixed后对单元格宽度设置无效在对设置表格设置table-layer:fixe...
- 大致思路是:建立两个table,一个table里只有thead,一个table里只有tbody,分别把两个tabl...
- 这几天在研究如何实现表格的固定列(fixed column)功能,这里记录了思路和细节。表格控件比较复杂,应用场景...