css实现三维分割旋转正方形效果

代码语言:html

所属分类:动画

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

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">

<style>
:root {
  --cube-w: 40vmin;
  --cube-h: calc(var(--cube-w) / 8);
  --side-z: calc(var(--cube-w) / 2);
  --perspective: calc(var(--cube-w) * 1.5);
  --duration: 1600ms;
  --ease: cubic-bezier(0.55, 0.055, 0.675, 0.19);
}

html, body {
  height: 100%;
}

body {
  display: grid;
  place-items: center;
  overflow: hidden;
  background-color: #C1B809;
}

.container {
  display: -webkit-box;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: reverse;
          flex-direction: column-reverse;
  position: relative;
  -webkit-perspective: var(--perspective);
          perspective: var(--perspective);
}

.cube {
  position: relative;
  width: var(--cube-w);
  height: var(--cube-h);
  -webkit-transform-style: preserve-3d;
          transform-style: preserve-3d;
  -webkit-animation: cube-rotation var(--duration) var(--ease) infinite;
          animation: cube-rotation var(--duration) var(--ease) infinite;
  -webkit-animation-delay: calc(var(--index) * 0.075s);
          animation-delay: calc(var(--index) * 0.075s);
}
.cube:nth-child(1) {
  z-index: 1;
}
.cube:nth-child(2) {
  z-index: 2;
}
.cube:nth-child(3) {
  z-index: 3;
}
.cube:nth-child(4) {
  z-index: 4;
}
.cube:nth-child(5) {
  z-index: 3;
}
.cube:nth-child(6) {
  z-index: 2;
}
.cube:nth-child(7) {
  z-index: 1;
}

.side {
  position: absolute;
  width: var(--cube-w);
  height: var(--cube-h);
  background-color: #3AE2C2;
  -webkit-animation-duration: var(--duration);
          animation-duration: var(--duration);
  -webkit-animation-timing-function: var(--ease);
          animation-timing-function: var(--ease);
  -webkit-animation-iteration-count: infinite;
          animation-iteration-count: infinite;
}
.side.front {
  -webkit-animation-name: front;
          animation-name: front;
  -webkit-animation-delay: calc(var(--index) * 0.075s);
          animation-delay: calc(var(--index) * 0.075s);
}
.side.left {
  -webkit-animation-name: left;
          animation-name: left;
  -webkit-animation-delay: calc(var(--index) * 0.075s);
          animation-delay: calc(var(--index) * 0.075s);
}
.side.back {
  -webkit-animation-name: back;
          animation-name: back;
  -webkit-animation-delay: calc(var(--index) * 0.075s);
          animation-delay: calc(var(--index) * 0.075s);
}

.front {
  -webkit-transform: translateZ(var(--side-z));
          transform: translateZ(var(--side-z));
}

.back {
  -webkit-transform: rotateY(180deg) translateZ(var(--side-z));
          transform: rotateY(180deg) translateZ(var(--side-z));
}

.right {
  -webkit-transform: rotateY(90deg) translateZ(var(--side-z));
          transform: rotateY(90deg) translateZ(var(--side-z));
}

.left {
  -webkit-transform: rotateY(-90deg) translateZ(var(--side-z));
          transform: rotateY(-90deg) translateZ(var(--side-z));
}

.top,
.bottom {
  height: var(--cube-w);
  background-color: #1ecbaa;
}

.top {
  -webkit-transform: rotateX(90deg) translateZ(var(--side-z));
          transform: rotateX(90deg) translateZ(var(--side-z));
}

.bottom {
  -webkit-transform: rotateX(-90deg) translateZ(calc(var(--cube-h) * -3));
          transform: rotateX(-90deg) translateZ(calc(var(--cube-h) * -3));
}

@-webkit-keyframes cube-rotation {
  60%, 100% {
    -webkit-transform: rotateY(0.5turn);
            transform: rotateY(0.5turn);
  }
}

@keyframes cube-rotation {
  60%, 100% {
    -webkit-transform: rotateY(0.5turn);
            transform: rotateY(0.5turn);
  }
}
@-webkit-keyframes front {
  0%, 25% {
    background-color: #3AE2C2;
  }
  40% {
    bac.........完整代码请登录后点击上方下载按钮下载查看

网友评论0