Div Drag 鼠标拖放

Standard
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<HTML>
<HEAD>
<TITLE> div-drag </TITLE>
<META NAME="Author" C>
<SCRIPT LANGUAGE="JavaScript">
var activeDiv,activeSpan,beforeDiv;
function active(e){
if(e.tagName=="SPAN"){
activeSpan = e;
return;
}
activeDiv = e.cloneNode(true);
document.body.insertBefore(activeDiv);
with(activeDiv.style){
position="absolute";
backgroundColor="yellow";
filter="alpha(opacity=50)";
left=event.x-20;
top=event.y;
}
activeDiv.srcElement=e;
activeDiv.;
}
function releaseDiv(){
if(!activeDiv) return;
document.body.removeChild(activeDiv)
var se = activeDiv.srcElement;
var p = se.parentNode;
activeDiv=null;
if(beforeDiv && beforeDiv==se) return;
if(beforeDiv && beforeDiv.parentNode==activeSpan)
activeSpan.insertBefore(p.removeChild(se),beforeDiv)
else
activeSpan.insertBefore(p.removeChild(se))
 
}
function moveDiv(){
if(!activeDiv) return;
with(activeDiv.style){
left=event.x-20;
top=event.y;
}
}
function before(e){
beforeDiv=e;
}
</SCRIPT>
</HEAD>
<BODY >
<span style="width:30%;height:100%;border:1px solid gray;overflow-y:auto" >
<SCRIPT>//自动生成假数据
for(var i=1;i<3;i++) document.write(" <div style=\"height:200px;cursor:hand;border:1px solid #CCFFFF;background-color:#99FFFF\" onmousedown=\"active(this)\" onmousemove=\"before(this)\"><span style=\"width:100\">"+i+"</span></div>")
</SCRIPT>
</span>
<span style="width:30%;height:100%;border:1px solid gray;overflow-y:auto" >
<SCRIPT>//自动生成假数据
for(var i=4;i<6;i++) document.write(" <div style=\"height:200px;cursor:hand;border:1px solid #CCFFFF;background-color:#FFFFCC\" onmousedown=\"active(this)\" onmousemove=\"before(this)\"><span style=\"width:100\">"+i+"</span></div>")
</SCRIPT>
</span>
<span style="width:30%;height:100%;border:1px solid gray;overflow-y:auto" >
<SCRIPT>//自动生成假数据
for(var i=7;i<9;i++) document.write(" <div style=\"height:200px;cursor:hand;border:1px solid #CCFFFF;background-color:#FFCCFF\" onmousedown=\"active(this)\" onmousemove=\"before(this)\"><span style=\"width:100\">"+i+"</span></div>")
</SCRIPT>
</span>
</BODY>
</HTML>
----------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> div-drag </TITLE>
<META NAME="Author" C>
<SCRIPT LANGUAGE="JavaScript">
var activeDiv,activeSpan,beforeDiv;
function active(e){
if(e.tagName=="SPAN"){
if(!activeDiv) return;
activeSpan = e;
if(activeDiv.srcElement.parentNode!=e)
before(e.lastChild);
return;
}
activeDiv = e.cloneNode(true);
document.body.insertBefore(activeDiv);
with(activeDiv.style){
position="absolute";
backgroundColor="yellow";
filter="alpha(opacity=50)";
left=event.x-20;
top=event.y+2;
}
activeDiv.srcElement=e;
activeDiv.;
activeDiv.;
}
function releaseDiv(){
if(!activeDiv) return;
document.body.removeChild(activeDiv)
var se = activeDiv.srcElement;
var p = se.parentNode;
activeDiv=null;
}
function moveDiv(){
if(!activeDiv) return;
with(activeDiv.style){
left=event.x-20;
top=event.y+2;
}
}
function before(e){
if(!activeDiv || e.nextSibling==activeDiv)return;
if(e!=activeDiv.srcElement)
if(e.nextSibling&&e.nextSibling.parentNode==e.parentNode&&e.nextSibling!=e.parentNode.lastChild)
e.parentNode.insertBefore(activeDiv.srcElement.parentNode.removeChild(activeDiv.srcElement),e.nextSibling)
else
e.parentNode.insertBefore(activeDiv.srcElement.parentNode.removeChild(activeDiv.srcElement))
}
</SCRIPT>
</HEAD>
<BODY >
<span style="width:30%;height:100%;border:1px solid gray;overflow-y:auto" >
<SCRIPT>//自动生成假数据
for(var i=1;i<3;i++) document.write(" <div style=\"height:200px;cursor:hand;border:1px solid #CCFFFF;background-color:#99FFFF\" onmousedown=\"active(this)\" onmousemove=\"before(this)\"><span style=\"width:100\">"+i+"</span></div>")
</SCRIPT>
</span>
<span style="width:30%;height:100%;border:1px solid gray;overflow-y:auto" >
<SCRIPT>//自动生成假数据
for(var i=4;i<6;i++) document.write(" <div style=\"height:200px;cursor:hand;border:1px solid #CCFFFF;background-color:#FFFFCC\" onmousedown=\"active(this)\" onmousemove=\"before(this)\"><span style=\"width:100\">"+i+"</span></div>")
</SCRIPT>
</span>
<span style="width:30%;height:100%;border:1px solid gray;overflow-y:auto" >
<SCRIPT>//自动生成假数据
for(var i=7;i<9;i++) document.write(" <div style=\"height:200px;cursor:hand;border:1px solid #CCFFFF;background-color:#FFCCFF\" onmousedown=\"active(this)\" onmousemove=\"before(this)\"><span style=\"width:100\">"+i+"</span></div>")
</SCRIPT>
</span>
</BODY>
</HTML>

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.