这个效果关键是逻辑,
流动效果
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
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>流动</title>
	<style>
		div{
			width:50px;
			height:50px;
			position: absolute;
			border-radius: 50%;
			top:0px;
			left:0px;
		}
	</style>
</head>
<body>
	<div style="background:red"></div>
	<div style="background:yellow"></div>
	<div style="background:purple"></div>
	<div style="background:green"></div>
	<div style="background:red"></div>
	<div style="background:gold"></div>
	<div style="background:red"></div>
	<div style="background:yellow"></div>
	<div style="background:purple"></div>
	<div style="background:green"></div>
	<div style="background:red"></div>
	<div style="background:gold"></div>
	<div style="background:red"></div>
	<div style="background:yellow"></div>
	<div style="background:purple"></div>
	<div style="background:green"></div>
	<div style="background:red"></div>
	<div style="background:gold"></div>
	<div style="background:red"></div>
	<div style="background:yellow"></div>
	<div style="background:purple"></div>
	<div style="background:green"></div>
	<div style="background:red"></div>
	<div style="background:gold"></div>
</body>
<script>
	window.onload=function(){
		document.onmousemove=function(event){
			var oEvent=event||window.event;
			var div=document.querySelectorAll("div");
			for(var i=div.length-1;i>0;i--){
				div[i].style.left=div[i-1].offsetLeft+"px";
				div[i].style.top=div[i-1].offsetTop+"px";
			};
			div[0].style.left=oEvent.clientX+"px";
			div[0].style.top=oEvent.clientY+"px";
		}
		var timer=setInterval(function(){
			var div=document.querySelectorAll("div");
			for(var i=div.length-1;i>0;i--){
				div[i].style.left=div[i-1].offsetLeft+"px";
				div[i].style.top=div[i-1].offsetTop+"px";
			}
		},40)
	}
</script>
</html>
