-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrag-table.html
64 lines (62 loc) · 1.89 KB
/
drag-table.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>火星黑洞</title>
</head>
<style>
td {
height: 60px;
}
</style>
<body>
<table id="table" cellspacing="0" cellpadding="1" width="100%" border="1">
<tbody>
<tr align="center" bgcolor="#1890ff">
<th>id</th>
<th>公司名称</th>
<th>姓名</th>
<th>岗位</th>
</tr>
<tr>
<td>20</td>
<td>科技有限公司</td>
<td>火星黑洞</td>
<td>web开发</td>
</tr>
</tbody>
</table>
<script type="text/javascript">
var tTD;
var table = document.getElementById("table");
console.log(table.rows[0].cells)
for (i = 0; i < table.rows[0].cells.length; i++) {
table.rows[0].cells[i].onmousedown = function() {
console.log('onmounseDown')
tTD = this;
if (event.offsetX > tTD.offsetWidth - 10) {
tTD.mouseDown = true;
tTD.oldX = event.x;
tTD.oldWidth = tTD.offsetWidth;
}
};
table.rows[0].cells[i].onmouseup = function() {
if (tTD == undefined) tTD = this;
tTD.mouseDown = false;
tTD.style.cursor = 'default';
};
table.rows[0].cells[i].onmousemove = function() {
if (event.offsetX > this.offsetWidth - 10)
this.style.cursor = 'col-resize';
else
this.style.cursor = 'default';
if (tTD == undefined) tTD = this;
if (tTD.mouseDown) {
tTD.width = tTD.oldWidth + (event.x - tTD.oldX); // 现在的宽度
tTD.style.cursor = 'col-resize';
}
};
}
</script>
</body>
</html>