var divList = [];
for (i = 0; i < 50; i++) {
var div = document.createElement("div");
var red = Math.round(Math.random() * 255);
var green = Math.round(Math.random() * 255);
var yellow = Math.round(Math.random() * 255);
div.style.borderColor = "rgb(" + red + "," + green + "," + yellow + ")";
document.body.appendChild(div);
divList[divList.length] = div;
}
document.onmousemove = function(e) {
var evt = window.event || e;
var x = evt.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft);
var y = evt.clientY + (document.documentElement.scrollTop || document.body.scrollTop);
divList[0].style.left = x + "px";
divList[0].style.top = y + "px";
for (i = divList.length - 1; i > 0; i--) {
divList[i].style.left = divList[i - 1].offsetLeft + "px";
divList[i].style.top = divList[i - 1].offsetTop + "px";
}
}
* {
margin: 0;
padding: 0;
}
div {
width: 50px;
height: 50px;
border-radius: 50%;
position: absolute;
border-width: 10px;
border-style: solid;
}
console