跟随鼠标的移动而移动的一串小球
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
padding: 0px;
margin: 0px;
}
div {
position: absolute;
width: 20px;
height: 20px;
background-color: yellow;
border-radius: 10px;
}
</style>
</head>
<body>
<script>
window.onload = function() {
var arr = document.getElementsByTagName("div");
document.onmousemove = function(ev) {
var e = ev || window.event;
for (var i = arr.length - 1; i > 0; i--) {
arr[i].style.left = arr[i - 1].offsetLeft + 'px';
arr[i].style.top = arr[i - 1].offsetTop + 'px';
}
arr[0].style.left = e.clientX + 'px';
arr[0].style.top = e.clientY + 'px';
}
}
</script>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</body>
</html>