4.1 requirements
1. In the frame of 800 * 800 every 2 SEC position randomly generated little squares, wide high for 5 px, color is green, with the increase of the survival time, wide high increases gradually, up to 10 px, the color gradually turn red;
2. The small square in the box moving randomly, each moving distance within the 5 px, cannot be removed from outside the box;
3. In the range of 200 * 200, if more than 10 small square, is the longest time square disappear;
CodePudding user response:
200 * 200 this what is the scope shall prevail?CodePudding user response:
May be like a big div is divided into 16 small div soCodePudding user response:
Can help have a lookCodePudding user response:
Should be easy to do, have time to do aCodePudding user response:
<meta charset="utf-8"/& gt;
<meta HTTP - equiv="X - UA - Compatible" content="IE=edge, chrome=1"/& gt;
<style type="text/css">
# box {
Width: 800 px;
Height: 800 px;
position: relative;
Border: 5 px solid # 999;
}
# box div {
Width: 5 px;
Height: 5 px;
Margin - left: - 2 px;
Margin - top: - 2 px;
position: absolute;
2 s linear transition: left, top 2 s linear;
Animation: an 10 s linear recently;
}
@ keyframes an {
0% {transform: scale (1); Background - color: # 0 f0; }
100% {transform: scale (2); Background - color: # f00; }
}
</style>
<body>
Var ds=box. GetElementsByTagName (" div ");
SetInterval (function () {
Var div=document. The createElement method (" div ");
Div. X=Math. Floor (Math. The random () * 780) + 10;
Div. Y=Math. Floor (Math. The random () * 780) + 10;
Div. Time=new Date (). GetTime ();
Box. The appendChild (div);
For (var arr=[]; Arr. Push ([]) & lt; 16);
For (var v, I=1; V=ds/+ + I) {
V.x +=Math. Floor (Math. The random (10) - 5;
V.y +=Math. Floor (Math. The random (10) - 5;
If (v.x & lt; 10) v.x=10;
If (v.y & lt; 10) v.y=10;
If (v.x & gt; 790) v.x=790;
If (v.y & gt; 790) v.y=790;
V. tyle. Left=v.x + "px";
V. tyle. Top=v.y + "px";
Arr [Math. Floor (v.y/200) * 4 + math.h floor (v.x/200)]. Push (v);
}
For (var v, I=1; V=arr [+ + I]) {
If (v.l ength> 10) {
V. ort (function (a, b) {
Return a.t ime - b.t ime.
});
[0] box. RemoveChild (v);
}
}
}, 2000);
</script>