console
function addPop() {
const span = document.createElement('span');
span.className = 'pop';
const size = Math.floor((Math.random() * 25) + 1);
const left = Math.floor((Math.random() * 25) + 43);
const duraction = Math.floor((Math.random() * 5) + 1);
const time = Math.floor((Math.random() * 5) + 1);
span.style.width = size + 'px';
span.style.height = size + 'px';
span.style.left = left + '%';
span.style.animation = `popMove ${time}s ${duraction}s linear infinite`;
const myblock = document.getElementById('myblock');
myblock.appendChild(span);
}
window.onload = function () {
for (let i = 0; i < 20; i++) {
addPop();
}
}
<button onclick="addPop()">add pop </button>
<div class="box">
<div class="myblock" id="myblock">
<div class="sun">
<div class="outCircle"></div>
<div class="innerCircle"></div>
<div class="text">15%</div>
</div>
<div class="field"></div>
<div class="pop" style="width:20px; height: 20px; left: 24%; animation: popMove 5s 3s linear infinite;"></div>
</div>
<div class="battery">
<div class="header"></div>
<div class="charge"></div>
<div class="cover">
<div class="wave1"></div>
<div class="wave2"></div>
</div>
</div>
</div>
* {
padding: 0;
margin: 0;
}
.box {
width: 800px;
height: 1800px;
margin: 0 auto;
background: black;
position: relative;
padding: 20px;
}
.battery {
width: 200px;
height: 320px;
background: white;
margin: 20px auto;
border-radius: 15px 15px;
position: relative;
}
.header {
width: 50px;
height: 20px;
background: white;
position: absolute;
left: 50%;
transform: translate(-50%, -20px);
border-radius: 5px 5px 0 0;
}
.charge {
position: absolute;
left: 0;
right: 0;
bottom: 0;
top: 95%;
background: linear-gradient(#7abcff 0%, #7bacff 40%, #8cafff 100%);
filter: hue-rotate(90deg);
animation: charge 5s linear infinite;
}
@keyframes charge {
0% {
border-radius: 0 0 15px 15px;
}
95% {
top: 5%;
border-radius: 0 0 15px 15px;
}
100% {
top: 0;
border-radius: 15px;
filter: hue-rotate(0deg);
}
}
.cover {
width: 100%;
height: 100%;
border-radius: 15px;
position: absolute;
left: 0;
top: 0;
overflow: hidden;
}
.wave1 {
width: 400px;
height: 400px;
background: rgba(255, 255, 255, 0.8);
position: absolute;
transform: translate(-25%, 0);
border-radius: 40% 30%;
animation: wave1 5s linear infinite;
}
.wave2 {
width: 400px;
height: 400px;
background: rgba(255, 255, 255, 0.4);
position: absolute;
transform: translate(-25%, 0);
border-radius: 30% 40%;
animation: wave2 5s linear infinite;
}
@keyframes wave1 {
0% {
transform: translate(-25%, 0) rotate(0deg);
bottom: 0%;
}
100% {
transform: translate(-25%, 0) rotate(360deg);
bottom: 100%;
}
}
@keyframes wave2 {
0% {
transform: translate(-25%, 0) rotate(30deg);
bottom: 0%;
}
100% {
transform: translate(-25%, 0) rotate(360deg);
bottom: 100%;
}
}
.myblock {
margin: 40px auto;
width: 200px;
height: 400px;
position: relative;
filter: contrast(15);
animation: hueRotate 10s linear infinite;
}
.sun {
position: relative;
width: 200px;
height: 200px;
}
.outCircle {
position: absolute;
background: greenyellow;
width: 150px;
height: 150px;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
border-radius: 40% 42% 64% 47%;
animation: circleRotate 10s linear infinite;
}
.innerCircle {
position: absolute;
background: black;
width: 133px;
height: 133px;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
border-radius: 50%;
}
@keyframes hueRotate {
0% {
filter: contrast(15) hue-rotate(0deg);
}
100% {
filter: contrast(15) hue-rotate(360deg);
}
}
@keyframes circleRotate {
0% {
transform: translate(-50%, -50%) rotate(0deg);
}
100% {
transform: translate(-50%, -50%) rotate(360deg);
}
}
.field {
position: absolute;
background: greenyellow;
bottom: 0;
width: 100px;
height: 30px;
border-radius: 65% 55% 25% 15%;
left: 50%;
transform: translate(-50%, 0);
}
.pop {
position: absolute;
background: greenyellow;
border-radius: 50%;
bottom: 0;
animation: popMove 5s 3s linear infinite;
}
@keyframes popMove {
0% {
bottom: 0;
}
100% {
bottom: 220px;
}
}
.text {
position: absolute;
color: white;
font-size: 24px;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}