-
Notifications
You must be signed in to change notification settings - Fork 34
/
drag.html
85 lines (83 loc) · 2.09 KB
/
drag.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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
img{
width:120px;
height:150px;
position:absolute;
}
</style>
</head>
<script type="text/javascript">
window.onload=function(){
var oImg=document.getElementsByTagName("img");
for(i=0;i<oImg.length;i++){
drag(oImg[i]);
}
function drag(obj){
obj.onmousedown=function(ev){
var ev=ev || event;
var disX=ev.clientX-this.offsetLeft;
var disY=ev.clientY-this.offsetTop;
if(obj.setCapture){
obj.setCapture();
}
document.onmousemove=function(ev){
var ev=ev || event;
var L=ev.clientX-disX;
var T=ev.clientY-disY;
if(L<0){
L=0;
}
else if(L>document.documentElement.clientWidth-obj.offsetWidth)
{
L=document.documentElement.clientWidth-obj.offsetWidth;
}
if(T<0){
T=0;
}
else if(T>document.documentElement.clientHeight-obj.offsetHeight)
{
T=document.documentElement.clientHeight-obj.offsetHeight;
}
obj.style.left=L+'px';
obj.style.top=T+'px';
}
document.onmouseup=function(){
document.onmousemove=document.onmouseover=null;
if(obj.releaseCapture){
obj.releaseCapture();
}
}
return false;
}
}
}
</script>
<body>
<img src="img/drag-img/1.jpg" />
<img src="img/drag-img/2.jpg" />
<img src="img/drag-img/3.jpg" />
<img src="img/drag-img/4.jpg" />
<img src="img/drag-img/5.jpg" />
<img src="img/drag-img/6.jpg" />
<img src="img/drag-img/7.jpg" />
<img src="img/drag-img/8.jpg" />
<img src="img/drag-img/9.jpg" />
<img src="img/drag-img/10.jpg" />
<img src="img/drag-img/11.jpg" />
<img src="img/drag-img/12.jpg" />
<img src="img/drag-img/13.jpg" />
<img src="img/drag-img/14.jpg" />
<img src="img/drag-img/15.jpg" />
<img src="img/drag-img/16.jpg" />
<img src="img/drag-img/17.jpg" />
<img src="img/drag-img/18.jpg" />
<img src="img/drag-img/19.jpg" />
<img src="img/drag-img/20.jpg" />
<img src="img/drag-img/21.jpg" />
</body>
</html>