水滴按钮解析

matlab 复制代码
<button class="button">
  <p>Button</p>
  <div class="liquid">
    <span style="--i:0"><span></span></span>
    <span style="--i:1"><span></span></span>
    <span style="--i:2"><span></span></span>
    <span style="--i:3"><span></span></span>
    <span style="--i:4"><span></span></span>
    <span style="--i:5"><span></span></span>
    <span style="--i:6"><span></span></span>
    <span class="bg"><span></span></span>
  </div>
  <svg>
    <filter id="gooey">
      <feGaussianBlur in="SourceGraphic" stdDeviation="10"></feGaussianBlur>
      <feColorMatrix
        values="1 0 0 0 0
          0 1 0 0 0 
          0 0 1 0 0
          0 0 0 20 -10"
      ></feColorMatrix>
    </filter>
  </svg>
</button>
matlab 复制代码
.button {
  background-color: transparent;
  border: none;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.button svg {
  width: 0;
  height: 0;
}

.button p {
  width: 150px;
  height: 60px;
  z-index: 9;
  font-size: 20px;
  color: white;
  text-align: center;
  cursor: pointer;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  transition: all 0.3s ease;
  text-shadow: 0 0 10px rgb(34, 143, 147);
  letter-spacing: 1px;
  user-select: none;
}

.button p:hover + .liquid span:not(.bg) {
  animation-play-state: running;
}

.button p:hover {
  transform: scale(1.1);
}

.button:active p {
  transform: scale(1);
}

.button .liquid {
  filter: url(#gooey);
  width: 150px;
  height: 200px;
  position: absolute;
  inset: 0;
}

.button .liquid > span {
  position: absolute;
  top: 1px;
  left: -35px;
  width: 100%;
  height: 100%;
  display: block;
  animation: rotate 2.5s ease infinite;
  animation-delay: calc(0.15s * var(--i));
  animation-play-state: paused;
}

.button .liquid > span > span {
  animation: move 6s ease-in-out infinite;
  animation-delay: calc(0.2s * var(--i));
  background: rgb(77, 159, 170);
  width: 50px;
  height: 50px;
  display: block;
  margin: auto;
  border-radius: 50%;
}

.button .liquid span > span::before {
  content: "";
  position: absolute;
  left: calc(50% - 20px);
  top: 0;
  width: 40px;
  height: 40px;
  background: linear-gradient(#2b7cc8, #23d2db);
  border-radius: 50%;
  box-shadow: 0 0 30px hsl(0, 0%, 69%);
}

.button .liquid span.bg {
  animation: none;
}
.button .liquid span.bg > span::before {
  width: 150px;
  height: 50px;
  left: calc(50% - 40px);
  border-radius: 20px;
}

.button .liquid span:nth-child(2) {
  left: -20px;
}
.button .liquid span:nth-child(1) {
  left: -40px;
}
.button .liquid span:nth-child(3) {
  left: -50px;
}
.button .liquid span:nth-child(4) {
  left: 20px;
}
.button .liquid span:nth-child(7) {
  left: 40px;
}
.button .liquid span:nth-child(6) {
  left: 50px;
}

@keyframes rotate {
  0% {
    transform: rotate(0deg);
  }
  80%,
  100% {
    transform: rotate(360deg);
  }
}

@keyframes move {
  0%,
  100% {
    transform: translateX(0) translateY(0) scale(1);
  }
  20% {
    transform: translateX(-8px) translateY(-4px) scale(1.1);
  }
  40% {
    transform: translateX(8px) translateY(8px) scale(0.9);
  }
  60% {
    transform: translateX(-8px) translateY(4px) scale(1.1);
  }
  80% {
    transform: translateX(5px) translateY(-8px) scale(0.9);
  }
}

@media (pointer: coarse), (pointer: none) {
  .button .liquid > span > span {
    background: transparent;
  }
}

主要是使用了svg 的高斯模糊创建了一种粘稠液体的特性然后在元素上使用css 的filter:url(#gooey)连接这种特性

相关推荐
于慨16 小时前
Lambda 表达式、方法引用(Method Reference)语法
java·前端·servlet
石小石Orz16 小时前
油猴脚本实现生产环境加载本地qiankun子应用
前端·架构
从前慢丶16 小时前
前端交互规范(Web 端)
前端
像我这样帅的人丶你还16 小时前
别再让JS耽误你进步了。
css·vue.js
@yanyu66616 小时前
07-引入element布局及spring boot完善后端
javascript·vue.js·spring boot
CHU72903516 小时前
便捷约玩,沉浸推理:线上剧本杀APP功能版块设计详解
前端·小程序
GISer_Jing17 小时前
Page-agent MCP结构
前端·人工智能
王霸天17 小时前
💥别再抄网上的Scale缩放代码了!50行源码教你写一个永不翻车的大屏适配
前端·vue.js·数据可视化
小领航17 小时前
用 Three.js + Vue 3 打造炫酷的 3D 行政地图可视化组件
前端·github
@大迁世界17 小时前
2026年React大洗牌:React Hooks 将迎来重大升级
前端·javascript·react.js·前端框架·ecmascript