一串跟随鼠标运动的DIV

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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
div{
width: 10px;
height: 10px;
background: red;
position: absolute;
}

</style>

</head>
<body>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<script>
var oDiv = document.getElementsByTagName("div");
var i = 0;
var mouseTop = 0;
var mouseLeft = 0;
document.onmousemove = function (ev){
var oEvent = ev || event;
for (i = oDiv.length-1; i > 0; i--) {
oDiv[i].style.left = oDiv[i-1].style.left;
oDiv[i].style.top = oDiv[i-1].style.top;
}

oDiv[0].style.left = oEvent.clientX+'px';
oDiv[0].style.top = oEvent.clientY+'px';

setTimeout(function (){
for (i = oDiv.length-1; i > 0; i--) {
oDiv[i].style.left = oEvent.clientX+'px';
oDiv[i].style.top = oEvent.clientY+'px';
}

}, 300);

}



</script>

</body>
</html>