代码的实现
for (let i = 0; i < 50; i++) {var box = document.createElement(\"div\");box.className = \"case\";console.log();$(\".main\").append(box);}$(\"<div class=item ></div>\").appendTo($(\".case\"));
$(\".item\").each(function (index, value) {var size = Math.random() * 50 + 10;var topRandom = Math.random() * $(\".main\").height();var leftRandom = Math.random() * $(\".main\").width();$(value).css({top: topRandom + \"px\",left: leftRandom + \"px\",width: size + \"px\",height: size + \"px\",backgroundColor: `hsla(${Math.random() * 360},50% ,70% ,${Math.random() + 0.2})`,});});
@keyframes caseMove {0% {transform: translateY(-100px);}100% {transform: translateY(700px);}}
@keyframes itemMove {0% {}50% {transform: translateX(-50px);}100% {}}
var index = 0;var timer = setInterval(function () {// index = Math.floor(Math.random() * $(\".item\").length);$(\".case\").eq(index).css({animation: \"caseMove 9s linear infinite\",})$(\".item\").eq(index).css({animation: \"itemMove 5s linear infinite\",})index++;console.log(index);}, 50)
if (index >= $(\".case\").length) {clearInterval(timer);timer = null;}
效果图