<! DOCTYPE html>
<meta charset= "UTF-8" >
<title>_ mouse movement Follow effect </title>
<style>
div {
width:50px;
height:50px;
border-radius:50%;
Position:absolute;
Text-align:center;
font-size:30px;
Color: #fff;
}
</style>
<script>
Let the first box follow the mouse position directly
The Back box changes position every few millimeters following the previous box.
Window.onload = function () {
var alldiv = document.getelementsbytagname ("div");//div array
Document.onmousemove = function (e) {
E = e | | window.event;//compatibility
Alldiv[0].style.top = E.clienty + "px";
Alldiv[0].style.left = E.clientx + "px";
}
Set timer
SetInterval (function () {
for (Var i=alldiv.length-1;i>0;i--) {
Alldiv[i].style.top = Alldiv[i-1].style.top;
Alldiv[i].style.left = Alldiv[i-1].style.left;
Alldiv[i].style.backgroundcolor = Randomcolor ();
}
},20)
Set Random Colors
function Randomcolor () {
var str = "0123456789abcdef";
var bgColor = "#";
for (var i = 0;i<6;i++) {
var temp = parseint (Str.length*math.random ());
BgColor + = temp;
}
return bgColor;
}
}
</script>
<body>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
<div>11</div>
<div>12</div>
<div>13</div>
<div>14</div>
<div>15</div>
<div>16</div>
<div>17</div>
<div>18</div>
<div>19</div>
<div>20</div>
<div>21</div>
<div>22</div>
<div>23</div>
<div>24</div>
<div>25</div>
<div>26</div>
<div>27</div>
<div>28</div>
<div>29</div>
<div>30</div>
<div>31</div>
<div>32</div>
<div>33</div>
<div>34</div>
<div>35</div>
<div>36</div>
<div>37</div>
<div>38</div>
<div>39</div>
<div>40</div>
<div>41</div>
<div>42</div>
<div>43</div>
<div>44</div>
<div>45</div>
<div>46</div>
<div>47</div>
<div>48</div>
<div>49</div>
<div>50</div>
</body>
_ Mouse Move Follow effect