-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path拖拽.html
49 lines (43 loc) · 1.05 KB
/
拖拽.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
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>拖拽</title>
<style>
* {
margin: 0;
padding: 0;
}
#drag {
width: 150px;
height: 200px;
background-color: red;
position: absolute;
cursor: pointer;
}
</style>
</head>
<body>
<h1>qqqqqqqqqqqqqqqqqqqqqqq</h1>
<div id="drag"></div>
<script>
var oDrag = document.getElementById("drag");
oDrag.onmousedown = function (e) {
e = e || window.event;
var iDisX = e.clientX - oDrag.offsetLeft;
var iDisY = e.clientY - oDrag.offsetTop;
document.onmousemove = function (e) {
e = e || window.event;
var Left = e.clientX - iDisX;
var Top = e.clientY - iDisY;
oDrag.style.left = Left + "px";
oDrag.style.top = Top + "px";
return false;
};
document.onmouseup = function () {
document.onmousemove = null;
}
}
</script>
</body>
</html>