div+css实现三维拟物态checkbox小球滚动开关效果代码

代码语言:html

所属分类:表单美化

代码描述:div+css实现三维拟物态checkbox小球滚动开关效果代码

代码标签: div css 三维 拟物 checkbox 小球 滚动 开关

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

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

<style>
    body {
  display: grid;
  place-items: center;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  background: linear-gradient(to top, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0.95)), linear-gradient(to bottom, #0070ff, #415fff);
}
body:before, body:after {
  content: "";
  position: absolute;
  width: 240px;
  height: 170px;
  left: calc(50% - 2.5px);
  top: 50%;
  transform: translate(-50%, -50%);
  background: #fff;
  pointer-events: none;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.85), 0 20px 40px 10px rgba(255, 255, 255, 0.85), 0 0 0 0.75px #415fff, 0 10px 40px -20px #0070ff, 0 20px 40px -20px #415fff;
}
body:after {
  box-shadow: none;
  background: linear-gradient(to bottom, #0070ff, #415fff);
  mix-blend-mode: soft-light;
  box-shadow: none;
  z-index: 9;
}
body #wrap {
  position: relative;
  width: 50px;
  height: 150px;
  transform-style: preserve-3d;
  perspective: 400px;
  transform: translateX(-75px);
}
body #wrap:before, body #wrap:after {
  content: "";
  position: absolute;
  width: 100%;
  height: 100%;
  background: #f2f2f2;
  left: calc(100% + 12.5px);
  transform-origin: left;
  transform: rotateY(90deg);
}
body #wrap:after {
  left: calc(-100% - 12.5px);
  transform-origin: right;
  transform: rotateY(-90deg);
}
body #wrap * {
  transform-style: preserve-3d;
}
body #wrap *:before, body #wrap *:after {
  transform-style: preserve-3d;
}
body #wrap label {
  z-index: 9;
  position: absolute;
  left: 75px;
  font-family: "Oswald";
  text-transform: uppercase;
  width: 200px;
  font-size: 24px;
  height: 50%;
  display: flex;
  align-items: center;
  top: 0;
  color: #fff;
  text-shadow: 0 -1px 2px #fff;
  transform: translateY(-2px) translateZ(-15px);
}
body #wrap label:before {
  content: attr(data-text);
  position: absolute;
  color: rgba(0, 0, 0, 0.25);
  z-index: -1;
  top: 50%;
  transform: translateY(calc(-50% + 2px));
  left: 0;
  filter: blur(2px);
}
body #wrap label:nth-of-type(2) {
  top: 50%;
}
body #wrap input {
  position: absolute;
  width: 100%;
  height: 50%;
  left: 0;
  opacity: 0;
  z-index: 999;
  cursor: pointer;
}
body #wrap input:first-of-type {
  top: 0;
}
body #wrap input:first-of-type:checked ~ .sphere {
  -webkit-animation: sphere1 0.75s ease-in-out 1 forwards, sphere3 0.75s ease-in-out 1 forwards;
          animation: sphere1 0.75s ease-in-out 1 forwards, sphere3 0.75s ease-in-out 1 forwards;
}
@-webkit-keyframes sphere1 {
  0% {
    box-shadow: inset 0px 2px 5px -2.5px rgba(0, 0, 0, 0.3), 0 0 5px 0 rgba(0, 0, 0, 0);
  }
  25% {
    box-shadow: inset 0px 3px 5px -2.5px rgba(0, 0, 0, 0.3), 0 0px 5px 0px rgba(0, 0, 0, 0);
  }
  62.5% {
    box-shadow: inset 0px 0px 5px -2.5px rgba(0, 0, 0, 0.3), 0 10px 10px 0px rgba(0, 0, 0, 0.1);
  }
  75% {
    box-shadow: inset -1px -1px 5px -2.5px rgba(0, 0, 0, 0.3), 0 10px 10px -5px rgba(0, 0, 0, 0.1);
  }
  100% {
    box-shadow: inset -1px -3px 5px -2.5px rgba(0, 0, 0, 0.3), 0 0 5px 0 rgba(0, 0, 0, 0);
  }
}
@keyframes sphere1 {
  0% {
    box-shadow: inset 0px 2px 5px -2.5px rgba(0, 0, 0, 0.3), 0 0 5px 0 rgba(0, 0, 0, 0);
  }
  25% {
    box-shadow: inset 0px 3px 5px -2.5px rgba(0, 0, 0, 0.3), 0 0px 5px 0px rgba(0, 0, 0, 0);
  }
  62.5% {
    box-shadow: inset 0px 0px 5px -2.5px rgba(0, 0, 0, 0.3), 0 10px 10px 0px rgba(0, 0, 0, 0.1);
  }
  75% {
    box-shadow: inset -1px -1px 5px -2.5px rgba(0, 0, 0, 0.3), 0 10px 10px -5px rgba(0, 0, 0, 0.1);
  }
  100% {
    box-shadow: inset -1px -3px 5px -2.5px rgba(0, 0, 0, 0.3), 0 0 5px 0 rgba(0, 0, 0, 0);
  }
}
@-webkit-keyframes sphere3 {
  0% {
    background-position: 50% 5px, center;
  }
  100% {
    background-position: 50% 0px, center;
  }
}
@keyframes sphere3 {
  0% {
    background-position: 50% 5px, center;
  }
  100% {
    background-position: 50% 0px, center;
  }
}
body #wrap input:first-of-type:checked ~ .platform {
  -webkit-animation: check1 0.75s ease-in-out 1 forwards;
          animation: check1 0.75s ease-in-out 1 forwards;
}
body #wrap input:first-of-type:checked ~ .platform:after {
  height: 40px;
  transform: translateY(10px) translateZ(40px) rotateX(80deg);
  background: linear-gradient(to top, rgba(0, 0, 0, 0.025), #efefef);
  box-shadow: 0 0 5px -3px #efefef;
}
@-webkit-keyframes check1 {
  0% {
    transform: rotateX(0deg);
    box-shadow: inset 0 -5px 5px -10px rgba(0, 0, 0, 0);
  }
  50% {
    transform: rotateX(40deg);
    box-shadow: inset 0 80px 35px -10px rgba(0, 0, 0, 0.035);
  }
  100% {
    transform: rotateX(0deg);
    box-shadow: inset 0 -5px 5px -10px rgba(0, 0, 0, 0);
  }
}
@keyframes check1 {
  0% {
    transform: rotateX(0deg);
    box-shadow: inset 0 -5px 5px -10px rgba(0, 0, 0, 0);
  }
  50% {
    transform: rotateX(40deg);
    box-shadow: inset 0 80px 35px -10px rgba(0, 0, 0, 0.035);
  }
  100% {
    transform: rotateX(0deg);
    box-shadow: inset 0 -5px 5px -10px rgba(0, 0, 0, 0);
  }
}
body #wrap input:first-of-type:checked ~ .platform .hole {
  -webkit-animation: hole1 0.75s ease-in-out 1 forwards;
          animation: hole1 0.75s ease-in-out 1 forwards;
}
@-webkit-keyframes hole1 {
  0% {
    box-shadow: 0 0 0 2px #fff, 0 1px 3px 3px #efefef, inset 0 3px 4px 3px #ddd;
  }
  50% {
    box-shadow: 0 0 0 2px #fff, 0 2px 3px 3px #efefef, inset 0 20px 4px 3px #ddd;
  }
  100% {
    box-shadow: 0 0 0 2px #fff, 0 1px 3px 3px #efefef, inset 0 3px 4px 3px #ddd;
  }
}
@keyframes hole1 {
  0% {
    box-shadow: 0 0 0 2px #fff, 0 1px 3px 3px #efefef, inset 0 3px 4px 3px #ddd;
  }
  50% {
    box-shadow: 0 0 0 2px #fff, 0 2px 3px 3px #efefef, inset 0 20px 4px 3px #ddd;
  }
  100% {
    box-shadow: 0 0 0 2px #fff, 0 1px 3px 3px #efefef, inset 0 3px 4px 3px #ddd;
  }
}
body #wrap input:last-of-type {
  bottom: 0;
}
body #wrap input:last-of-type:checked ~ .sphere {
  transform: translateZ(90px) translateX(-50%) translateY(55px);
  -webkit-animation: sphere2 0.75s ease.........完整代码请登录后点击上方下载按钮下载查看

网友评论0