div+css实现漩涡开关切换效果代码

代码语言:html

所属分类:其他

代码描述:div+css实现漩涡开关切换效果代码

代码标签: div css 漩涡 开关 切换

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

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

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



  
  
  
<style>
body {
  margin: 0
}

* {
  box-sizing: border-box;
}

input {
  display: none;
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  height: 0;
  width: 0;
}

.container {
  background-color: #333333;
  background-image: radial-gradient(transparent, rgb(0 0 0 / 45%));
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  width: 100vw;
}

.switch {
  border: 3px solid #252525;
  box-shadow: 0 0 35px 5px inset, 0 0 3px 1px;
  border-radius: 100px;
  height: 120px;
  width: 250px;
  position: relative;
  padding: 10px;
  transition: background-color 0.63s 0.06s;
}

.overlay:before {
  top: -40px;
}

.overlay:after {
  bottom: -40px;
}

label {
  position: absolute;
  top: -3px;
  height: calc(100% + 6px);
  width: calc(50% + 3px);
  cursor: pointer;
  z-index: 1;
}

label[for="switch-on"] {
  left: -3px;
}

label[for="switch-off"] {
  right: -3px;
}

.pin-wrapper {
  position: relative;
  height: 100%;
  width: 100%;
}

.pin {
  position: absolute;
  top: 0;
  height: 94px;
  width: 94px;
  background: #57575791;
  border-radius: 50%;
  box-shadow: 0 0 2px #939393, 0 0 17px #434343 inset, 2px -3px 12px 5px #181818 inset;
  transition: background 0.32s;
}

.pin:after,
.pin-center:before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
  opacity: 0;
}

.pin:after {
  border-radius: 50%;
  pointer-events: none;
  transition: opacity 0.61s ease-in;
}

.pin-off:after {
  box-shadow: 0 0 22px -1px #d13c3c;
}

.pin-on:after {
  box-shadow: 0 0 22px -1px #3cd148;
}

label[for="switch-on"]:hover ~ .pin-wrapper .pin-on:after,
label[for="switch-off"]:hover ~ .pin-wrapper .pin-off:after {
  opacity: 0.7;
  transition: opacity 0.32s;
}

.pin-center:before {
  transition: 0.62s 0.02s;
  transform: scale(0.91);
}

.pin-on {
  left: 0;
}

.pin-off {
  right: 0;
  transform: scale(-1, 1);
}

input#switch-on:checked ~ .switch {
  background-color: rgba(58, 79, 51, 0.9);
}

input#switch-off:checked ~ .switch {
  background-color: rgba(79, 51, 51, 0.9); 
}

input#switch-on:checked ~ .switch .pin-on .pin-corners,
input#switch-off:checked ~ .switch .pin-off .pin-corners {
  transform: rotate(-42.5deg);
}

.pin-corners {
  position: relative;
  height: 100%;
  width: 100%;
  border-radius: 50%;
  overflow: hidden;
  transition: 0.78s;
}

.pin-corners span {
  position: absolute;
  top: 0;
  left: 0;
  height: 49px;
  width: 40px;
  border-right: 2px solid #5d5d5d;
  border-radius: 30px 15px 25% / 150% 0;
  transform-origin: 47px 47px;
  transition: border-color 0.42s;
}

input#switch-on:checked ~ .switch .pin-on .pin-corners span,
input#switch-off:checked ~ .switch .pin-off .pin-corners span {
  border-color: #383838;
  transition: border-color 0.42s 0.21s ease-out;
}

.pin-corners span:nth-child(1) {
  transform: rotate(0deg);
}

.pin-corners span:nth-child(2) {
  transform: rotate(30deg);
}

.pin-corners span:nth-child(3) {
  transform: rotate(60deg);
}

.pin-corners span:nth-child(4) {
  transform: rotate(90deg);
}

.pin-corners span:nth-child(5) {
  transform: rotate(120deg);
}

.pin-corners span:nth-child(6) {
  transform: rotate(150deg);
}

.pin-corners span:nth-child(7) {
  transform: rotate(180deg);
}

.pin-corners span:nth-child(8) {
  transform: rotate(210deg);
}

.pin-corners span:nth-child(9) {
  transform: rot.........完整代码请登录后点击上方下载按钮下载查看

网友评论0