今天在B站上,看到了一个使用HTML和CSS,实现动态水滴的效果https://www.bilibili.com/video/BV1Qy4y1L7ot,感觉挺好玩的,就试了式。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
body {
background: #1e90ff;
}
.main {
height: 400px;
width: 400px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
box-sizing: border-box;
background: transparent;
border-radius: 42% 58% 61% 39% / 32% 32% 68% 68% ;
box-shadow: inset 10px 20px 30px rgba(0, 0, 0, .5),
10px 10px 20px rgba(0, 0, 0, .3),
15px 15px 30px rgba(0, 0, 0, .3),
inset -10px -10px 15px rgba(255, 255, 255, .7);
animation: move 8s linear infinite;
}
/* 使用伪类添加两个高亮 */
.main::after{
content: '';
width: 40px;
height: 40px;
background: rgba(255, 255, 255, .8);
border-radius: 50%;
position: absolute;
top:80px;
left: 60px;
}
.main::before{
content: '';
width: 20px;
height: 20px;
background: rgba(255, 255, 255, .8);
border-radius: 50%;
position: absolute;
top:60px;
left: 110px;
}
/* 使用动画,让水滴动起来*/
@keyframes move {
25%{
border-radius:42% 58% 43% 57% / 32% 34% 66% 68% ;
}
50%{
border-radius: 42% 58% 51% 49% / 32% 27% 73% 68% ;
}
75%{
border-radius: 42% 58% 62% 38% / 32% 37% 63% 68% ;
}
}
</style>
</head>
<body>
<div class="main"></div>
</body>
</html>
效果如下: