<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
div {
width: 10px;
height: 10px;
background-color: lawngreen;
border-radius: 50%;
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>
<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>
<div></div>
<script type="text/javascript">
var divs = document.getElementsByTagName("div");
// 一串跟着动,核心是onmousemove
document.onmousemove = function() {
// 先取得第一个div的left和top值,根据鼠标的坐标来确定
divs[0].style.left = event.clientX + "px";
divs[0].style.top = event.clientY + "px";
for (var i = divs.length - 1; i > 0; i--) {
divs[i].style.left = divs[i - 1].style.left;
divs[i].style.top = divs[i - 1].style.top;
}
document.onmouseup = function(){
document.onmousemove = null;
}
}
</script>
</body>
</html>