水滴按钮解析

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)连接这种特性

相关推荐
0思必得010 分钟前
[Web自动化] Selenium处理滚动条
前端·爬虫·python·selenium·自动化
Misnice12 分钟前
Webpack、Vite、Rsbuild区别
前端·webpack·node.js
青茶36013 分钟前
php怎么实现订单接口状态轮询(二)
前端·php·接口
大橙子额1 小时前
【解决报错】Cannot assign to read only property ‘exports‘ of object ‘#<Object>‘
前端·javascript·vue.js
RFCEO1 小时前
前端编程 课程十六、:CSS 盒子模型
css·前端基础课程·css盒子模型·css盒子模型的组成·精准控制元素的大小和位置·css布局的基石·内边距(padding)
WooaiJava2 小时前
AI 智能助手项目面试技术要点总结(前端部分)
javascript·大模型·html5
爱喝白开水a2 小时前
前端AI自动化测试:brower-use调研让大模型帮你做网页交互与测试
前端·人工智能·大模型·prompt·交互·agent·rag
Never_Satisfied2 小时前
在JavaScript / HTML中,关于querySelectorAll方法
开发语言·javascript·html
董世昌412 小时前
深度解析ES6 Set与Map:相同点、核心差异及实战选型
前端·javascript·es6
WeiXiao_Hyy3 小时前
成为 Top 1% 的工程师
java·开发语言·javascript·经验分享·后端