-
Notifications
You must be signed in to change notification settings - Fork 0
/
move8.html
47 lines (47 loc) · 1.01 KB
/
move8.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>运动8</title>
<style type="">
div{
width: 20px;
height: 20px;
background: red;
position: absolute;
}
</style>
<script type="text/javascript">
//鼠标运动事件
function getPos(ev){
var oEvent=ev||event;
var scrollTop=document.documentElement.scrollTop||document.body.scrollTop;
var scrollLeft=document.documentElement.scrollLeft||document.body.scrollLeft;
return {X:oEvent.clientX+scrollLeft,Y:oEvent.clientY+scrollTop};
}
window.onload=function(){
var oDiv=document.getElementsByTagName("div");
document.onmousemove=function(ev){
var pos=getPos(ev);
for(var i=oDiv.length-1; i>0; i--){
oDiv[i].style.left=oDiv[i-1].offsetLeft+'px';
oDiv[i].style.top=oDiv[i-1].offsetTop+'px';
}
oDiv[0].style.left=pos.X+'px';
oDiv[0].style.top=pos.Y+'px';
}
}
</script>
</head>
<body>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</body>
</html>