svgjs+svg实现动感流畅checkbox开关点击动画效果代码

代码语言:html

所属分类:其他

代码描述:svgjs+svg实现动感流畅checkbox开关点击动画效果代码

代码标签: svgjs svg 动感 流畅 checkbox 开关 点击 动画

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

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

<head>
  <meta charset="UTF-8">
  

  
<style>
@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@300&display=swap");
html,
body {
  height: 100%;
}

body {
  background-color: #3d3e4a;
  display: flex;
  justify-content: center;
  align-items: center;
  color: #a3a7ad;
  font-family: "IBM Plex Mono", monospace;
  font-weight: 300;
  font-style: normal;
  font-size: 12px;
  flex-direction: column;
  margin: 15px;
}

h1 {
  color: #76b3fa;
  font-size: 18px;
  margin-bottom: 30px;
}

.wrapper {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  margin: 10px;
}

.input-container {
  border-radius: 8px;
  display: flex;
  align-items: center;
  flex-direction: column;
  margin: 10px 20px;
}

.control-label {
  background-color: #24252c;
  background-image: repeating-linear-gradient(0deg, #181a29, #181a29 2px, #202436 2px, #202436 4px);
  border: 2px solid #575969;
  border-radius: 4px;
  display: block;
  width: 84px;
  height: 36px;
  position: relative;
  transition: border-color 300ms ease-in-out, box-shadow 300ms ease-in-out;
  margin-bottom: 15px;
}

input[type=checkbox] {
  display: none;
}

input[type=checkbox]:checked + label {
  border-color: #76b3fa;
  box-shadow: 0 0 20px 0 #0763f7, inset 0px 0px 12px 0px #0763f7;
}
input[type=checkbox]:checked + label svg rect {
  fill: #76b3fa;
}

svg rect {
  fill: #484a57;
  transition: fill 300ms ease-in-out;
}
svg .reference rect {
  opacity: 0;
}
</style>

  
  
</head>

<body translate="no">
  <h1>Silky smooth checkbox toggles</h1>

<div class="wrapper">
  <div class="input-container">
    <input id="slide-toggle-control" type="checkbox" value="1" />
    <label id="slide-toggle-label" for="slide-toggle-control" class="control-label">
      <svg height="36" width="100" xmlns="http://www.w3.org/2000/svg">
        <g class="switch">
          <g class="row">
            <rect x="6" y="6" width="2" height="2" />
            <rect x="8" y="6" width="2" height="2" />
            <rect x="10" y="6" width="2" height="2" />
            <rect x="12" y="6" width="2" height="2" />
            <rect x="14" y="6" width="2" height="2" />
            <rect x="16" y="6" width="2" height="2" />
            <rect x="18" y="6" width="2" height="2" />
            <rect x="20" y="6" width="2" height="2" />
            <rect x="22" y="6" width="2" height="2" />
            <rect x="24" y="6" width="2" height="2" />
            <rect x="26" y="6" width="2" height="2" />
            <rect x="28" y="6" width="2" height="2" />
          </g>

          <g class="row">
            <rect x="6" y="8" width="2" height="2" />
            <rect x="8" y="8" width="2" height="2" />
            <rect x="10" y="8" width="2" height="2" />
            <rect x="12" y="8" width="2" height="2" />
            <rect x="14" y="8" width="2" height="2" />
            <rect x="16" y="8" width="2" height="2" />
            <rect x="18" y="8" width="2" height="2" />
            <rect x="20" y="8" width="2" height="2" />
            <rect x="22" y="8" width="2" height="2" />
            <rect x="24" y="8" width="2" height="2" />
            <rect x="26" y="8" width="2" height="2" />
            <rect x="28" y="8" width="2" height="2" />
          </g>

          <g class="row">
            <rect x="6" y="10" width="2" height="2" />
            <rect x="8" y="10" width="2" height="2" />
            <rect x="10" y="10" width="2" height="2" />
            <rect x="12" y="10" width="2" height="2" />
            <rect x="14" y="10" width="2" height="2" />
            <rect x="16" y="10" width="2" height="2" />
            <rect x="18" y="10" width="2" height="2" />
            <rect x="20" y="10" width="2" height="2" />
            <rect x="22" y="10" width="2" height="2" />
            <rect x="24" y="10" width="2" height="2" />
            <rect x="26" y="10" width="2" height="2" />
            <rect x="28" y="10" width="2" height="2" />
          </g>

          <g class="row">
            <rect x="6" y="12" width="2" height="2" />
            <rect x="8" y="12" width="2" height="2" />
            <rect x="10" y="12" width="2" height="2" />
            <rect x="12" y="12" width="2" height="2" />
            <rect x="14" y="12" width="2" height="2" />
            <rect x="16" y="12" width="2" height="2" />
            <rect x="18" y="12" width="2" height="2" />
            <rect x="20" y="12" width="2" height="2" />
            <rect x="22" y="12" width="2" height="2" />
            <rect x="24" y="12" width="2" height="2" />
            <rect x="26" y="12" width="2" height="2" />
            <rect x="28" y="12" width="2" height="2" />
          </g>

          <g class="row">
            <rect x="6" y="14" width="2" height="2" />
            <rect x="8" y="14" width="2" height="2" />
            <rect x="10" y="14" width="2" height="2" />
            <rect x="12" y="14" width="2" height="2" />
            <rect x="14" y="14" width="2" height="2" />
            <rect x="16" y="14" width="2" height="2" />
            <rect x="18" y="14" width="2" height="2" />
            <rect x="20" y="14" width="2" height="2" />
            <rect x="22" y="14" width="2" height="2" />
            <rect x="24" y="14" width="2" height="2" />
            <rect x="26" y="14" width="2" height="2" />
            <rect x="28" y="14" width="2" height="2" />
          </g>

          <g class="row">
            <rect x="6" y="16" width="2" height="2" />
            <rect x="8" y="16" width="2" height="2" />
            <rect x="10" y="16" width="2" height="2" />
            <rect x="12" y="16" width="2" height="2" />
            <rect x="14" y="16" width="2" height="2" />
            <rect x="16" y="16" width="2" height="2" />
            <rect x="18" y="16" width="2" height="2" />
            <rect x="20" y="16" width="2" height="2" />
            <rect x="22" y="16" width="2" height="2" />
            <rect x="24" y="16" width="2" height="2" />
            <rect x="26" y="16" width="2" height="2" />
            <rect x="28" y="16" width="2" height="2" />
          </g>

          <g class="row">
            <rect x="6" y="18" width="2" height="2" />
            <rect x="8" y="18" width="2" height="2" />
            <rect x="10" y="18" width="2" height="2" />
            <rect x="12" y="18" width="2" height="2" />
            <rect x="14" y="18" width="2" height="2" />
            <rect x="16" y="18" width="2" height="2" />
            <rect x="18" y="18" width="2" height="2" />
            <rect x="20" y="18" width="2" height="2" />
            <rect x="22" y="18" width="2" height="2" />
            <rect x="24" y="18" width="2" height="2" />
            <rect x="26" y="18" width="2" height="2" />
            <rect x="28" y="18" width="2" height="2" />
          </g>

          <g class="row">
            <rect x="6" y="20" width="2" height="2" />
            <rect x="8" y="20" width="2" height="2" />
            <rect x="10" y="20" width="2" height="2" />
            <rect x="12" y="20" width="2" height="2" />
            <rect x="14" y="20" width="2" height="2" />
            <rect x="16" y="20" width="2" height="2" />
            <rect x="18" y="20" width="2" height="2" />
            <rect x="20" y="20" width="2" height="2" />
            <rect x="22" y="20" width="2" height="2" />
            <rect x="24" y="20" width="2" height="2" />
            <rect x="26" y="20" width="2" height="2" />
            <rect x="28" y="20" width="2" height="2" />
          </g>

          <g class="row">
            <rect x="6" y="22" width="2" height="2" />
            <rect x="8" y="22" width="2" height="2" />
            <rect x="10" y="22" width="2" height="2" />
            <rect x="12" y="22" width="2" height="2" />
            <rect x="14" y="22" width="2" height="2" />
            <rect x="16" y="22" width="2" height="2" />
            <rect x="18" y="22" width="2" height="2" />
            <rect x="20" y="22" width="2" height="2" />
            <rect x="22" y="22" width="2" height="2" />
            <rect x="24" y="22" width="2" height="2" />
            <rect x="26" y="22" width="2" height="2" />
            <rect x="28" y="22" width="2" height="2" />
          </g>

          <g class="row">
            <rect x="6" y="24" width="2" height="2" />
            <rect x="8" y="24" width="2" height="2" />
            <rect x="10" y="24" width="2" height="2" />
            <rect x="12" y="24" width="2" height="2" />
            <rect x="14" y="24" width="2" height="2" />
            <rect x="16" y="24" width="2" height="2" />
            <rect x="18" y="24" width="2" height="2" />
            <rect x="20" y="24" width="2" height="2" />
            <rect x="22" y="24" width="2" height="2" />
            <rect x="24" y="24" width="2" height="2" />
            <rect x="26" y="24" width="2" height="2" />
            <rect x="28" y="24" width="2" height="2" />
          </g>

          <g class="row">
            <rect x="6" y="26" width="2" height="2" />
            <rect x="8" y="26" width="2" height="2" />
            <rect x="10" y="26" width="2" height="2" />
            <rect x="12" y="26" width="2" height="2" />
            <rect x="14" y="26" width="2" height="2" />
            <rect x="16" y="26" width="2" height="2" />
            <rect x="18" y="26" width="2" height="2" />
            <rect x="20" y="26" width="2" height="2" />
            <rect x="22" y="26" width="2" height="2" />
            <rect x="24" y="26" width="2" height="2" />
            <rect x="26" y="26" width="2" height="2" />
            <rect x="28" y="26" width="2" height="2" />
          </g>

          <g class="row">
            <rect x="6" y="28" width="2" height="2" />
            <rect x="8" y="28" width="2" height="2" />
            <rect x="10" y="28" width="2" height="2" />
            <rect x="12" y="28" width="2" height="2" />
            <rect x="14" y="28" width="2" height="2" />
            <rect x="16" y="28" width="2" height="2" />
            <rect x="18" y="28" width="2" height="2" />
            <rect x="20" y="28" width="2" height="2" />
            <rect x="22" y="28" width="2" height="2" />
            <rect x="24" y="28" width="2" height="2" />
            <rect x="26" y="28" width="2" height="2" />
            <rect x="28" y="28" width="2" height="2" />
          </g>
        </g>
      </svg>
    </label>
    <label for="slide-toggle-control">
      Offset
    </label>
  </div>

  <div class="input-container">
    <input id="random-slide-toggle-control" type="checkbox" value="1" />
    <label id="random-slide-toggle-label" for="random-slide-toggle-control" class="control-label">
      <svg height="36" width="100" xmlns="http://www.w3.org/2000/svg">
        <g class="switch">
          <g class="row">
            <rect x="6" y="6" width="2" height="2" />
            <rect x="8" y="6" width="2" height="2" />
            <rect x="10" y="6" width="2" height="2" />
            <rect x="12" y="6" width="2" height="2" />
            <rect x="14" y="6" width="2" height="2" />
            <rect x="16" y="6" width="2" height="2" />
            <rect x="18" y="6" width="2" height="2" />
            <rect x="20" y="6" width="2" height="2" />
            <rect x="22" y="6" width="2" height="2" />
            <rect x="24" y="6" width="2" height="2" />
            <rect x="26" y="6" width="2" height="2" />
            <rect x="28" y="6" width="2" height="2" />
          </g>

          <g class="row">
            <rect x="6" y="8" width="2" height="2" />
            <rect x="8" y="8" width="2" height="2" />
            <rect x="10" y="8" width="2" height="2" />
            <rect x="12" y="8" width="2" height="2" />
            <rect x="14" y="8" width="2" height="2" />
            <rect x="16" y="8" width="2" height="2" />
            <rect x="18" y="8" width="2" height="2" />
            <rect x="20" y="8" width="2" height="2" />
            <rect x="22" y="8" width="2" height="2" />
            <rect x="24" y="8" width="2" height="2" />
            <rect x="26" y="8" width="2" height="2" />
            <rect x="28" y="8" width="2" height="2" />
          </g>

          <g class="row">
            <rect x="6" y="10" width="2" height="2" />
            <rect x="8" y="10" width="2" height="2" />
            <rect x="10" y="10" width="2" height="2" />
            <rect x="12" y="10" width="2" height="2" />
            <rect x="14" y="10" width="2" height="2" />
            <rect x="16" y="10" width="2" height="2" />
            <rect x="18" y="10" width="2" height="2" />
            <rect x="20" y="10" width="2" height="2" />
            <rect x="22" y="10" width="2" height="2" />
            <rect x="24" y="10" width="2" height="2" />
            <rect x="26" y="10" width="2" height="2" />
            <rect x="28" y="10" width="2" height="2" />
          </g>

          <g class="row">
            <rect x="6" y="12" width="2" height="2" />
            <rect x="8" y="12" width="2" height="2" />
            <rect x="10" y="12" width="2" height="2" />
            <rect x="12" y="12" width="2" height="2" />
            <rect x="14" y="12" width="2" height="2" />
            <rect x="16" y="12" width="2" height="2" />
            <rect x="18" y="12" width="2" height="2" />
            <rect x="20" y="12" width="2" height="2" />
            <rect x="22" y="12" width="2" height="2" />
            <rect x="24" y="12" width="2" height="2" />
            <rect x="26" y="12" width="2" height="2" />
            <rect x="28" y="12" width="2" height="2" />
          </g>

          <g class="row">
            <rect x="6" y="14" width="2" height="2" />
            <rect x="8" y="14" width="2" height="2" />
            <rect x="10" y="14" width="2" height="2" />
            <rect x="12" y="14" width="2" height="2" />
            <rect x="14" y="14" width="2" height="2" />
            <rect x="16" y="14" width="2" height="2" />
            <rect x="18" y="14" width="2" height="2" />
            <rect x="20" y="14" width="2" height="2" />
            <rect x="22" y="14" width="2" height="2" />
            <rect x="24" y="14" width="2" height="2" />
            <rect x="26" y="14" width="2" height="2" />
            <rect x="28" y="14" width="2" height="2" />
          </g>

          <g class="row">
            <rect x="6" y="16" width="2" height="2" />
            <rect x="8" y="16" width="2" height="2" />
            <rect x="10" y="16" width="2" height="2" />
            <rect x="12" y="16" width="2" height="2" />
            <rect x="14" y="16" width="2" height="2" />
            <rect x="16" y="16" width="2" height="2" />
            <rect x="18" y="16" width="2" height="2" />
            <rect x="20" y="16" width="2" height="2" />
            <rect x="22" y="16" width="2" height="2" />
            <rect x="24" y="16" width="2" height="2" />
            <rect x="26" y="16" width="2" height="2" />
            <rect x="28" y="16" width="2" height="2" />
          </g>

          <g class="row">
            <rect x="6" y="18" width="2" height="2" />
            <rect x="8.........完整代码请登录后点击上方下载按钮下载查看

网友评论0