div {
width: 10px;
height: 10px;
background: red;
position: absolute;
}
<div></div>
<div></div>
<div></div>
<div></div>
window.onload = function() {
//获取所有的div
var aDiv = document.getElementsByTagName('div');
var i = 0;
//当鼠标移动
document.onmousemove = function(ev) {
var oEvent = ev || event;
for (i = aDiv.length - 1; i > 0; i--) {
aDiv[i].style.left = aDiv[i - 1].style.left;
aDiv[i].style.top = aDiv[i - 1].style.top;
}
//跟着鼠标走
aDiv[0].style.left = oEvent.clientX + 'px';
aDiv[0].style.top = oEvent.clientY + 'px';
};
}