svg实现一个液体按钮效果代码

代码语言:html

所属分类:表单美化

代码描述:svg实现一个液体按钮效果代码,鼠标放上去试试

代码标签: 液体 按钮 效果

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开


<!DOCTYPE html>
<html lang="en" >

<head>

  <meta charset="UTF-8">
  

  
  
<style>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  position: relative;
  display: grid;
  height: 100vh;
  place-items: center;
  background: #ede9fe;
  overflow: hidden;
  color: #4c1d95;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

svg {
  overflow: visible;
}

.wobble {
  position: relative;
  width: 256px;
  height: 56px;
  background: none;
  border: none;
  color: #f5f3ff;
  cursor: pointer;
  font-family: "Nunito", sans-serif;
  font-weight: 700;
  font-size: 1rem;
  overflow: visible;
  outline: none;
}

.wobble svg {
  /*   filter: drop-shadow(0px 8px 16px rgba(139, 92, 246, 0.75)); */
  overflow: visible;
}

.wobble #btnPath {
  stroke: transparent;
  stroke-width: 3;
}

.wobble > * {
  pointer-events: none !important;
}

.wobble:focus #btnPath {
  stroke-width: 3;
  stroke: #fcd34d;
}

.wobble svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
}

.toggle-points {
}

.blob {
  position: absolute;
  bottom: -25%;
  right: -25%;
  width: 50vw;
}

.blob path {
  fill: #ddd6fe;
}

.blob:nth-of-type(2) {
  top: -25%;
  left: -25%;
  bottom: auto;
  right: auto;
}

.debug-text {
  font-family: "Nunito", sans-serif;
  position: absolute;
  bottom: 1rem;
  left: 1rem;
  cursor: pointer;
}

.debug-dot {
  opacity: 0;
}

.debug .debug-dot {
  opacity: 1 !important;
}
</style>


</head>

<body  >
  <button class="wobble">
  Liquid SVG Button 💛
  <svg width="256" height="56" viewBox="0 0 256 56" fill="none" xmlns="http://www.w3.org/2000/svg">
    <defs>
      <linearGradient id="gradient" gradientTransform="rotate(90)">
        <stop offset="5%" stop-color="#7C3AED" />
        <stop offset="95%" stop-color="#8B5CF6" />
      </linearGradient>
      <filter id="shadow" filterUnits="userSpaceOnUse" height="200" width="512" y="0">
        <feDropShadow dx="0" dy="8" stdDeviation="8" flood-color="#7C3AED" flood-opacity="0.3" />
      </filter>
    </defs>
    <path id="baseBtnPath" d="M0 28C0 12.536 12.536 0 28 0H228C243.464 0 256 12.536 256 28C256 43.464 243.464 56 228 56H28C12.536 56 0 43.464 0 28Z" fill="transparent" />
  </svg>
</button>
<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg" class="blob">
  <path fill="#FF0066" d="M60.7,-18.7C68.8,5.1,58.6,35.9,36.5,52.6C14.3,69.3,-19.9,71.9,-42.9,55.9C-65.9,40,-77.7,5.4,-68.7,-19.7C-59.7,-44.9,-29.8,-60.7,-1.8,-60.2C26.3,-59.6,52.6,-42.6,60.7,-18.7Z" transform="translate(100 100)" />
</svg>

<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg" class="blob">
  <path fill="#C4B5FD" d="M43,-45.3C54.5,-31.4,61.9,-15.7,64.4,2.5C66.9,20.7,64.4,41.3,52.9,54.9C41.3,68.4,20.7,74.9,4.3,70.7C-12.1,66.4,-24.2,51.3,-40.5,37.7C-56.9,24.2,-77.5,12.1,-83.1,-5.6C-88.7,-23.3,-79.3,-46.6,-63,-60.5C-46.6,-74.3,-23.3,-78.7,-3.8,-74.9C15.7,-71.1,31.4,-59.1,43,-45.3Z" transform="translate(100 100)" />
</svg>
<p class="debug-text">Toggle Debug Mode</p>

  
      <script  type="module">
import SVG from "https://cdn.skypack.dev/svg.js";
import {
spline,
map } from
"https://cdn.skypack.dev/@georgedoescode/generative-utils@1.0.0";
import { Vector2D } from "h.........完整代码请登录后点击上方下载按钮下载查看

网友评论0