纯前端实现以下效果:
页面结构如下:
<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
</head>
<body>
<div class="wrapper">
<div class="green">
<div class="progress">
<div class="inner">
<div class="percent"><span>25</span>%</div>
<div class="water"></div>
<div class="glare"></div>
</div>
</div>
</div>
</div>
</body>
</html>
Css如下:
<style>
* {
box-sizing: border-box;
}
html,
body {
height: 100%;
}
body {
background-color: #1a1a1a;
}
.green .progress {
position: relative;
border-radius: 50%;
/* 以下三个数字就是这个控件的大小 */
width: 150px;
height: 150px;
line-height: 150px;
/* 以上三个数字就是这个控件的大小 */
border: 5px solid #53fc53;
box-shadow: 0 0 20px #029502;
transition: all 1s ease;
}
.green .progress .inner .water {
/* 调整这个百分比,就是显示的水深 */
top: 75%;
}
.wrapper {
display: flex;
-o-box-align: center;
align-items: center;
-o-box-pack: center;
justify-content: center;
-o-box-orient: vertical;
flex-direction: column;
height: 100%;
}
.green {
margin-top: 15px;
width: 100%;
height: 100%;
}
.green .progress .inner {
position: absolute;
overflow: hidden;
z-index: 2;
border-radius: 50%;
width: 100%;
height: 100%;
border: 5px solid #1a1a1a;
transition: all 1s ease;
}
.green .progress .inner .water {
position: absolute;
z-index: 1;
width: 200%;
height: 200%;
left: -50%;
border-radius: 40%;
-webkit-animation-iteration-count: infinite;
animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
animation-timing-function: linear;
-webkit-animation-name: spin;
animation-name: spin;
background: rgba(83, 252, 83, 0.5);
transition: all 1s ease;
-webkit-animation-duration: 10s;
animation-duration: 10s;
box-shadow: 0 0 20px #03bc03;
}
.green .progress .inner .glare {
position: absolute;
top: -120%;
left: -120%;
z-index: 5;
width: 100%;
height: 100%;
transform: rotate(45deg);
border-radius: 50%;
background-color: rgba(255, 255, 255, 0.15);
transition: all 1s ease;
}
.green .progress .inner .percent {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
font-weight: bold;
text-align: center;
font-size: 15px;
color: #03c603;
text-shadow: 0 0 10px #029502;
transition: all 1s ease;
}
@-webkit-keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
@keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
</style>