react实现跷跷板开关效果代码

代码语言:html

所属分类:其他

代码描述:react实现跷跷板开关效果代码

代码标签: react 跷跷板 开关

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

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

<head>
  <meta charset="UTF-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">

  
  
<style>
@import url("https://fonts.googleapis.com/css?family=Merriweather:700|Roboto");
html {
  font-family: "Roboto", sans-serif;
  background-color: #ded6ec;
  min-height: 100dvh;
}

.header {
  color: #583740;
  max-width: min(80vw, 700px);
  text-align: center;
}

.appWrapper {
  margin-bottom: 5rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.toggleContainer {
  --width: 100px;
  --halfWidth: calc(var(--width) / 2);
  --height: calc(2 * sin(var(--pivotAngle)) * var(--halfWidth));
  --pivotAngle: 25deg;
  --negPivotAngle: calc(var(--pivotAngle) * -1);
  --seeSawCol: black;
  --animSpeed: 0.5s;
  display: block;
  cursor: pointer;
  position: relative;
  width: var(--width);
  height: var(--height);
  margin: 4rem 0;
}
.toggleContainer .pivot {
  --halfHeight: calc(var(--height) / 2);
  --quartHeight: calc(var(--height) / 4);
  position: absolute;
  left: 50%;
  bottom: 5%;
  transform: translate(-50%, 20%);
  width: 0;
  height: 0;
  border-left: var(--quartHeight) solid transparent;
  border-right: var(--quartHeight) solid transparent;
  border-bottom: var(--halfHeight) solid var(--seeSawCol);
}
.toggleContainer .title {
  position: absolute;
  top: calc(100% + 0.75rem);
  left: 50%;
  transform: translateX(-50%);
  font-weight: bold;
  font-size: 12px;
  color: #583740;
  text-align: center;
  -webkit-user-select: none;
     -moz-user-select: none;
      -ms-user-select: none;
          user-select: none;
}
.toggleContainer .seeSaw {
  position: absolute;
  top: 50%;
  width: 100%;
  height: 5px;
  pointer-events: none;
  background-color: var(--seeSawCol);
  border-radius: 10px;
  -webkit-animation-duration: var(--animSpeed);
          animation-duration: var(--animSpeed);
  -webkit-animation-timing-function: ease-in;
          animation-timing-function: ease-in;
  -webkit-animation-fill-mode: forwards;
          animation-fill-mode: forwards;
  -webkit-animation-name: reversePivot;
          animation-name: reversePivot;
}
.toggleContainer .bit {
  aspect-ratio: 1/1;
  position: absolute;
  top: 0;
  left: 3%;
  -webkit-animation-duration: var(--animSpeed);
          animation-duration: var(--animSpeed);
  -webkit-animation-timing-function: ease-in;
          animation-timing-function: ease-in;
  -webkit-animation-fill-mode: forwards;
          animation-fill-mode: forwards;
  -webkit-animation-name: jump;
          animation-name: jump;
  transform: translateY(-70%);
  -webkit-user-select: none;
     -moz-user-select: none;
      -ms-user-select: none;
          user-select: none;
}
.toggleContainer .bit.alt {
  right: 3%;
  left: auto;
  -webkit-animation-name: fling;
          animation-name: fling;
}
.toggleContainer input {
  opacity: 0;
  width: 0;
  height: 0;
}
.toggleContainer input:checked ~ .seeSaw {
  -webkit-animation-name: pivot;
          animation-name: pivot;
}
.toggleContainer input:checked ~ .bit {
  -webkit-animation-name: fling;
          animation-name: fling;
  opacity: 0.4;
}
.toggleContainer input:checked ~ .bit.alt {
  -webkit-animation-name: jump;
          animation-name: jump;
  opacity: 1;
}

@-webkit-keyframes pivot {
  0% {
    transform: rotate(var(--negPivotAngle));
  }
  35% {
    transform: rotate(-var(--negPivotAngle));
  }
  70% {
    transform: rotate(var(--pivotAngle));
  }
  100% {
    transform: rotate(var(--pivotAngle));
  }
}

@keyframes pivot {
  0% {
    transform: rotate(var(--negPivotAngle));
  }
  35% {
    transform: rotate(-var(--negPivotAngle));
  }
  70% {
    transform: rotate(var(--pivotAngle));
  }
  100% {
    transform: rotate(var(--pivotAngle));
  }
}
@-webkit-keyframes reversePivot {
  0% {
    transform: rotate(var(--pivotAngle));
  }
  35% {
    transform: rotate(var(--pivotAngle));
  }
  70% {
    transform: rotate(var(--negPivotAngle));
  }
  100% {
    transform: rotate(var(--negPivotAngle));.........完整代码请登录后点击上方下载按钮下载查看

网友评论0