forked from jikeytang/jikeytang.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
98 lines (98 loc) · 3.61 KB
/
index.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>表格的行拖动</title>
<link rel="stylesheet" type="text/css" href="../../css/bootstrap.min.css" media="all"/>
<link rel="stylesheet" type="text/css" href="../../css/bootstrap-theme.min.css" media="all"/>
<link rel="stylesheet" type="text/css" href="../../css/reset.css" media="all"/>
<style type="text/css">
.demo{ position:relative; width:600px;margin:50px auto; text-align:left; padding:0; }
.list{ color:#2a6496;}
.list li{ position:relative; width:320px;list-style:decimal inside;line-height:35px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
.list a{font-size:18px;}
.tip{position:absolute;left: 0;display:none;color:#fff;background:rgba(0,0,0, 0.6); line-height:25px;font-size:12px;padding:2px 5px;border-radius:5px;z-index:1}
.ellipsis{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
.table{border-collapse:collapse; border:1px solid #ccc;}
.table th, .table td{ padding:0 8px;line-height:35px; border:1px solid #ccc;background: #fff;}
.table th{background: #f5f5f5;}
.table tr:nth-child(even) td{background: #dff0d8;}
.table tr:hover td{background: #fcf8e3;}
.table tr.on td{background: #d9edf7;}
.table td.mv{cursor:move;}
</style>
</head>
<body>
<div id="div" class="demo">
<table class="table">
<tr>
<th>表头内容</th>
<th>表头内容</th>
<th>表头内容</th>
</tr>
<tr>
<td>此处拖动</td>
<td>表格内容2</td>
<td>表格内容2</td>
</tr>
<tr>
<td>此处拖动</td>
<td>表格内容2</td>
<td>表格内容2</td>
</tr>
<tr>
<td>此处拖动</td>
<td>表格内容2</td>
<td>表格内容2</td>
</tr>
<tr>
<td>此处拖动</td>
<td>表格内容2</td>
<td>表格内容2</td>
</tr>
<tr>
<td>此处拖动</td>
<td>表格内容2</td>
<td>表格内容2</td>
</tr>
</table>
</div>
<script>
(function(){
var div = document.getElementById('div');
var tab = div.getElementsByTagName('table')[0];
var tr = tab.getElementsByTagName('tr');
var tb = tab.tBodies[0];
var startY = 0;
var tmp = null;
for(var i = 1; i < tr.length; i++){
var td = tr[i].cells[0];
td.className = 'mv';
td.onmousedown = function(e){
e = e || event;
startY = e.clientY;
console.log(startY);
tmp = td.parentNode.cloneNode(true);
var d = document.createElement('div');
d.className = 'lay';
d.style.cssText = 'position:absolute;top:'+startY+'px;width:600px;';
d.innerHTML = '<table width="600" class="table"></table>';
d.children[0].appendChild(tmp);
div.appendChild(d);
e.preventDefault();
window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
td.onmousemove = function(e){
e = e || event;
d.style.top = e.clientY + 'px'
}
document.onmouseup = function(){
div.removeChild(d);
td.onmousemove = null;
document.onmouseup = null;
}
}
}
}());
</script>
</body>
</html>