<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>js表格上下左右拖动代码 - 更多源码【www.96flw.com】</title>
</head>
<style>
body {
margin: 0;
padding: 0;
}
.scroll-table-demo {
height: 100vh;
display: flex;
flex-direction: column;
}
.scroll-table-title {
height: 80px;
line-height: 24px;
font-weight: bold;
background-color: #7fd75a;
color: #fff;
display: flex;
align-items: center;
padding-left: 20px;
}
/* 全局css配置 */
.scroll-table {
height: calc(100% - 80px);
}
.scroll-table table {
border: none;
border-collapse: collapse;
}
.scroll-table td,
.scroll-table th {
padding: 0;
}
.scroll-table-container {
display: flex;
height: 100%;
overflow: hidden;
}
/* scroll-table-left */
.scroll-table-left,
.scroll-table-slider {
display: flex;
flex-direction: column;
box-shadow: 1px 3px 5px #eee;
}
.scroll-table-left-top,
.scroll-table-slider-top {
height: 45px;
background-color: #f5f7fa;
position: relative;
z-index: 10;
}
.scroll-table-right-top {
background-color: #f5f7fa;
}
.scroll-table-left-top div,
.scroll-table-slider div {
width: 60px;
height: 45px;
line-height: 45px;
text-align: center;
}
.scroll-table-left-top tr,
.scroll-table-slider-top tr {
border-bottom: 1px solid #ebeef5;
}
.scroll-table-left-freeze,
.scroll-table-slider-freeze {
flex: 1;
height: calc(100% - 45px - 45px);
/* background-color: #e1f3d8; */
}
.scroll-table-left-freeze tr,
.scroll-table-slider-freeze tr {
border-bottom: 1px solid #ebeef5;
box-sizing: border-box;
}
.scroll-table-left-freeze td>div,
.scroll-table-slider-freeze td>div {
width: 60px;
height: 45px;
line-height: 45px;
text-align: center;
}
.scroll-table-left-bottom,
.scroll-table-slider-bottom {
height: 45px;
background-color: #f5f7fa;
position: relative;
z-index: 10;
}
.scroll-table-left-bottom tr,
.scroll-table-slider-bottom .tr {
margin: 0;
padding: 0;
}
.scroll-table-left-bottom th>div,
.scroll-table-slider-bottom th>div {
width: 60px;
}
/* scroll-table-right */
.scroll-table-right {
overflow: hidden;
flex: 1;
display: flex;
flex-direction: column;
}
.scroll-table-right-bottom {
background-color: #1890ff;
color: #fff;
}
.scroll-table-right-bottom td>div {
width: 90px;
height: 45px;
line-height: 45px;
text-align: center;
}
.scroll-table-right-top tr {
border-bottom: 1px solid #ebeef5;
background-color: #f5f7fa;
}
.scroll-table-right-top th>div {
width: 90px;
height: 45px;
line-height: 45px;
text-align: center;
}
.scroll-table-right-content {
flex: 1;
overflow: hidden;
}
.scroll-table-right-content tr {
border-bottom: 1px solid #ebeef5;
}
.scroll-table-right-content td>div {
width: 90px;
height: 45px;
line-height: 45px;
text-align: center;
}
</style>
<body>
<div id="app">
<div class="scroll-table-demo">
<div class="scroll-table-title">
scroll-table</br>
表格顶部上下左固定 内容滚动
</div>
<div class="scroll-table">
<div class="scroll-table-container">
<!-- left -->
<div class="scroll-table-left">
<!-- 上 -->
<table class="scroll-table-left-top">
<tbody>
<tr>
<th>
<div>姓名</div>
</th>
</tr>
</tbody>
</table>
<!-- 中 -->
<div class="scroll-table-left-freeze">
<table style="transform:translate(0px, 0px) translateZ(0px)">
<tr v-for="item in 30">
<td>
<div>张三</div>
</td>
</tr>
</table>
</div>
<!-- 下 -->
<table class="scroll-table-left-bottom">
<tbody>
<tr>
<th>
<div>总计</div>
</th>
</tr>
</tbody>
</table>
</div>
<!-- right -->
<div class="scroll-table-right">
<!-- 上 -->
<div class="scroll-table-right-top">
<table class="freeze-top" style="transform:translate(0px, 0px) translateZ(0px)">
<tbody>
<tr>
<th v-for="item in hd">
<div>{{item}}</div>
</th>
</tr>
</tbody>
</table>
</div>
<!-- 中 -->
<div class="scroll-table-right-content">
<table style="transform:translate(0px, 0px) translateZ(0px)">
<tbody>
<tr v-for="item in 30">
<td v-for="item1 in bd">
<div>{{item1}}</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- 下 -->
<div class="scroll-table-right-bottom">
<table class="freeze-bottom" style="transform:translate(0px, 0px) translateZ(0px)">
<tbody>
<tr>
<td v-for="item in ft">
<div>{{item}}</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
<script src="js/bscroll.js"></script>
<script src="js/vue.min.js"></script>
<script>
new Vue({
el: "#app",
data: {
hd: ['语文', '数学', '英语', '物理', '化学', '生物', '地理', '政治', '历史'],
bd: [99, 66, 77, 88, 99, 59, 77, 8