-
Notifications
You must be signed in to change notification settings - Fork 6
/
027-跟随鼠标的一串div.html
48 lines (48 loc) · 999 Bytes
/
027-跟随鼠标的一串div.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
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style>
div{ background:red; width:50px; height:50px; position:absolute;}
</style>
<script>
/*
*/
document.onmousemove = function(ev)
{
var aDiv = document.getElementsByTagName("div");
document.onmousemove = function(ev)
{
var oEvent = ev || event;
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft;
for(var i = aDiv.length - 1; i > 0; i--)
{
aDiv[i].style.top = aDiv[i - 1].style.top;
aDiv[i].style.left = aDiv[i - 1].style.left;
}
aDiv[0].style.top = oEvent.clientY + scrollTop + "px";
aDiv[0].style.left = oEvent.clientX + scrollLeft + "px";
}
}
</script>
</head>
<body style="height:2000px;">
<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>
<div></div>
</body>
</html>