-
Notifications
You must be signed in to change notification settings - Fork 0
/
adsorbent.html
84 lines (83 loc) · 2.24 KB
/
adsorbent.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>自动吸附</title>
<style type="text/css">
div{
width: 250px;
height: 250px;
background: red;
position: absolute;
}
</style>
<script type="text/javascript">
//鼠标拖拽事件
window.onload=function(){
var oDiv=document.getElementsByTagName('div')[0];
oDiv.onmousedown=function(ev){
var oEvent=ev||event;
var ox=oEvent.clientX-oDiv.offsetLeft;
var oy=oEvent.clientY-oDiv.offsetTop;
oDiv.style.left=oEvent.clientX-ox+'px';
oDiv.style.top=oEvent.clientY-oy+'px';
if(oDiv.setCapture){
oDiv.onmousemove=function(ev){
var oEvent=ev||event;
var flag=document.clientX
var X=oEvent.clientX-ox;
var Y=oEvent.clientY-oy;
if(X<50)
X=0;
else if(X>document.documentElement.clientWidth-oDiv.offsetWidth-50)
X=document.documentElement.clientWidth-oDiv.offsetWidth;
if(Y<50)
Y=0;
else if(Y>document.documentElement.clientHeight-oDiv.offsetHeight-50)
Y=document.documentElement.clientHeight-oDiv.offsetHeight;
oDiv.style.left=X+'px';
oDiv.style.top=Y+'px';
}
oDiv.onmouseup=function(){
oDiv.onmousemove=null;
oDiv.onmouseup=null;
oDiv.releaseCapture();
}
oDiv.setCapture();
return false;
}
else{
document.onmousemove=function(ev){
var oEvent=ev||event;
var flag=document.clientX
var X=oEvent.clientX-ox;
var Y=oEvent.clientY-oy;
if(X<50)
X=0;
else if(X>document.documentElement.clientWidth-oDiv.offsetWidth-50)
X=document.documentElement.clientWidth-oDiv.offsetWidth;
if(Y<50)
Y=0;
else if(Y>document.documentElement.clientHeight-oDiv.offsetHeight-50)
Y=document.documentElement.clientHeight-oDiv.offsetHeight;
oDiv.style.left=X+'px';
oDiv.style.top=Y+'px';
}
document.onmouseup=function(){
this.onmousemove=null;
this.onmouseup=null;
}
return false;
}
}
}
</script>
</head>
<body>
jdfkjklsdjfksj <br>
jdfkjdskljfklsdjf <br>
hdfkjdsfksdf <br>
iuritwpwepokl <br>
<div>拉我慢慢靠近窗口边缘,看我吸附的能力,而且我经过屏幕的其他文字,不会把它们选中</div>
</body>
</html>