gsap实现液态checkbox radio button点击动画效果代码

代码语言:html

所属分类:表单美化

代码描述:gsap实现液态checkbox radio button点击动画效果代码

代码标签: checkbox radio button 点击 动画 效果

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


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

<head>

  <meta charset="UTF-8">
  

  <link rel='stylesheet' href='https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;700&amp;display=swap'>
  
<style>
:root {
  --c-active: #275EFE;
  --c-active-inner: #FFFFFF;
  --c-default: #D2D6E9;
  --c-default-dark: #C7CBDF;
  --c-black: #1B1B22;
}

.radio,
.checkbox,
.switch {
  display: table;
  border-radius: var(--border-radius, 12px) var(--border-radius-corner, 12px) var(--border-radius, 12px) var(--border-radius, 12px);
  position: relative;
}
.radio input,
.checkbox input,
.switch input {
  -webkit-appearance: none;
     -moz-appearance: none;
          appearance: none;
  outline: none;
  border: none;
  background: var(--input-background, none);
  display: block;
  cursor: pointer;
  margin: 0;
  padding: 0;
  border-radius: inherit;
  width: var(--input-width, 24px);
  height: var(--input-height, 24px);
}
.radio svg,
.checkbox svg,
.switch svg {
  display: block;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  top: 0;
  pointer-events: none;
  fill: var(--c-active-inner);
  transform: scale(1.01) translateZ(0);
}

.radio input,
.checkbox input {
  --border-color: var(--c-default);
  --border-width: 2px;
  box-shadow: inset 0 0 0 var(--border-width) var(--border-color);
}
.radio input:checked,
.checkbox input:checked {
  --border-color: var(--c-active);
}
.radio input:not(:checked),
.checkbox input:not(:checked) {
  transition: box-shadow 0.25s;
}
.radio input:not(:checked):hover,
.checkbox input:not(:checked):hover {
  --border-width: 3px;
  --border-color: var(--c-active);
}

.radio input:checked {
  --border-width: 6.75px;
}
.radio input + svg {
  --top-y: 0;
  --dot-y: -17px;
  --drop-y: -14px;
  --top-s-x: 1.75;
  --top-s-y: 1;
}
.radio input + svg .top {
  transform-origin: 12px -12px;
  transform: translateY(var(--top-y)) scale(var(--top-s-x), var(--top-s-y)) translateZ(0);
}
.radio input + svg .dot {
  transform: translateY(var(--dot-y)) translateZ(0);
}
.radio input + svg .drop {
  transform: translateY(var(--drop-y)) translateZ(0);
}

.checkbox {
  --border-radius: 5px;
  --border-radius-corner: 5px;
}
.checkbox input:checked {
  --border-width: 12px;
}
.checkbox input:checked + svg {
  --tick-offset: 46.5px;
}
.checkbox input + svg {
  --dot-x: 14px;
  --dot-y: -14px;
  --dot-s: 1;
  --tick-offset: 20.5px;
  --tick-array: 16.5px;
  --tick-s: 1;
  --drop-s: 1;
}
.checkbox input + svg .tick {
  fill: none;
  stroke-width: 3px;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke: var(--c-active-inner);
  stroke-dasharray: var(--tick-array) 33px;
  stroke-dashoffset: var(--tick-offset);
  transform-origin: 10.5px 16px;
  transform: scale(var(--tick-s)) translateZ(0);
}
.checkbox input + svg .dot {
  transform-origin: 10.5px 15.5px;
  transform: translate(var(--dot-x), var(--dot-y)) scale(var(--dot-s)) translateZ(0);
}
.checkbox input + svg .drop {
  transform-origin: 25px -1px;
  transform: scale(var(--drop-s)) translateZ(0);
}

.switch {
  --input-width: 38px;
}
.switch input {
  --input-background: var(--c-default);
}
.switch input:checked {
  --input-background: var(--c-active);
}
.switch input:checked + svg {
  --default-s: 0;
  --default-x: 8px;
  --dot-s: 1;
  --dot-x: 0px;
}
.switch input + svg {
  --input-background: var(--c-default);
  --default-s: 1;
  --default-x: 0px;
  --dot-s: 0;
  --dot-x: -8px;
}
.switch .default {
  transform-origin: 12px 12px;
  transform: translateX(var(--default-x)) scale(var(--default-s)) translateZ(0);
}
.switch .dot {
  transform-origin: 26px 12px;
  transform: translateX(var(--dot-x)) scale(var(--dot-s)) translateZ(0);
}

.btn {
  -webkit-appearance: none;
     -moz-appearance: none;
          appearance: none;
  border: none;
  position: relative;
  background: var(--c-black);
  color: #fff;
  outline: none;
  cursor: pointer;
  font-size: 14px;
  line-height: 21px;
  font-weight: 600;
  display: block;
  width: 132px;
  text-align: center;
  border-radius: 7px;
  margin: 0 auto;
  padding: 12px 0;
}
.btn span {
  position: relative;
  z-index: 1;
}
.btn svg {
  display: block;
  width: 100%;
  height: 100%;
  position: absolute;
  left: 0;
  top: 0;
  fill: var(--c-active);
}
.btn svg circle {
  transition: transform var(--duration, 0.25s) ease-out;
}
.btn svg circle.top-left {
  transform: translate(var(--spacing, -16px), var(--spacing, -40px));
}
.btn svg circle.middle-bottom {
  transform: translate(var(--spacing, 8px), var(--spacing, 40px));
}
.btn svg circle.top-right {
  transform: translate(var(--spacing, 40px), var(--spacing, -40px));
}
.btn svg circle.right-bottom {
  transform: translate(var(--spacing, 4px), var(--spacing, 40px));
}
.btn svg circle.left-bottom {
  transform: translate(var(--spacing, -40px), var(--spacing, 40px));
}
.btn:hover {
  --spacing: 0;
  --duration: .45s;
}

.grid {
  display: grid;
  grid-gap: 24px 32px;
  grid-template-columns: repeat(3, auto);
  grid-template-rows: repeat(3, auto);
  grid-auto-flow: column;
}
.grid .last {
  grid-column: 1/4;
  grid-row: 3;
}

html {
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
}

* {
  box-sizing: inherit;
}
*:before, *:after {
  box-sizing: inherit;
}

body {
  min-height: 100vh;
  display: flex;
  font-family: "Poppins", Arial;
  justify-content: center;
  align-items: center;
  background: #fff;
}
body .dribbble {
  position: fixed;
  display: block;
  right: 20px;
  bottom: 20px;
}
body .dribbble img {
  display: block;
  height: 28px;
}
body .twitter {
  position: fixed;
  display: block;
  right: 64px;
  bottom: 14px;
}
body .twitter svg {
  width: 32px;
  height: 32px;
  fill: #1da1f2;
}
</style>



</head>

<body >
  <div class="grid">

    <label class="radio">
        <input type="radio" name="r" value="1" checked />
        <svg viewBox="0 0 24 24" filter="url(#goo-light)">
            <circle class="top" cx="12" cy="-12" r="8" />
            <circle class="dot" cx="12" cy="12" r="5" />
            <circle class="drop" cx="12" cy="12" r="2" />
        </svg>
    </label>

    <label class="radio">
        <input type="radio" name="r" value="2" />
        <svg viewBox="0 0 24 24" filter="url(#goo-light)">
            <circle class="top" cx="12" cy="-12" r="8" />
            <circle class="dot" cx="12" cy="12" r="5" />
            <circle class="drop" cx="12" cy="12" r="2" />
        </svg>
    </label>

    <label class="switch">
        <input type="checkbox" checked />
        <svg viewBox="0 0 38 24" filter="url(#goo)">
            <circle class="default" cx="12" cy="12" r="8" />
            <circle class="dot" cx="26" cy="12" r="8" />
            <circle class="drop" cx="25" cy="-1" r="2" />
        </svg>
    </label>

    <label class="switch">
        <input type="checkbox" />
        <svg viewBox="0 0 38 24" filter="url(#goo)">
            <circle class="default" cx="12" cy="12" r="8" />
            <circle class="dot" cx="26" cy="12" r="8" />
        </svg>
    </label>

    <label class="checkbox">
        <input type="checkbox" checked />
        <svg viewBox="0 0 24 24" filter="url(#goo-light)">
            <path class="tick" d="M4.5 10L10.5 16L24.5 1" />
            <circle class="dot" cx="10.5" cy="15.5" r="1.5" />
        </svg>
    </label>

    <l.........完整代码请登录后点击上方下载按钮下载查看

网友评论0