div+css实现三维钻石球旋转动画效果代码

代码语言:html

所属分类:动画

代码描述:div+css实现三维钻石球旋转动画效果代码

代码标签: div css 三维 钻石 旋转 动画

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

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

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


  
  
<style>
input {
  display: none;
}

body {
  margin: 0;
  height: 100vh;
  background-image: linear-gradient(to bottom right, transparent, #333);
  font-size: .6vmin;
}

body * {
  position: absolute;
}

.wrapper {
  position: absolute;
  inset: 0;
  background-image: linear-gradient(to bottom left, #000, #011, #303);
  display: grid;
  animation: hue 2s ease-in-out infinite alternate;
}

@keyframes hue {
  0% {
    filter: saturate(4) contrast(1.5) hue-rotate(180deg);
  }
  100% {
    filter: saturate(5) contrast(2) hue-rotate(360deg);
  }
}

.playBtn {
  display: block;
  width: 30em;
  aspect-ratio: 1;
  background-color: black;
  align-self: end;
  margin: 10em;
  clip-path: polygon(0 0, 40% 20%, 40% 20%, 60% 30%, 60% 30%, 100% 50%, 100% 50%, 0 100%);
  transition: all .5s ease-in-out;
  transform-origin: 0 100%;
}

.playBtn:hover {
  scale: 1.2;
}

#playPause:checked ~ .wrapper .playBtn {
  clip-path: polygon(0 0, 40% 0%, 40% 100%, 60% 100%, 60% 0, 100% 0, 100% 100%, 0 100%);
}

#playPause:not(:checked) ~ .wrapper,
#playPause:not(:checked) ~ .wrapper :is(.pivot, .starHedron, .triangle),
#playPause:not(:checked) ~ .wrapper .pentagon::before {
  animation-play-state: paused;
}

.scene {
  place-self: center;
  width: 100em;
  aspect-ratio: 1;
  perspective: 250em;
}

.scene * {
  transform-style: preserve-3d;
}

.pivot, .starHedron {
  inset: 0;
}

.pivot {
  animation: wobble 8s ease-in-out alternate infinite;
}

@keyframes wobble {
  0% {
    rotate: x -30deg;
  }
  100% {
    rotate: x 30deg;
  }
}

.starHedron {
  display: grid;
  place-items: center;
  animation: spin 9s linear infinite;
}

@keyframes spin {
  0% {
    rotate: y 1deg;
  }
  100% {
    rotate: y 361deg;
  }
}

.pentagon {
  --pentaW: calc(sin(atan(1/(cos(36deg) + .5))) * 100); 
  width: calc(var(--pentaW)*1em);
  aspect-ratio: 1;
  --pushZ: calc(cos(atan(1/(cos(36deg) + .5))) * 50);
  display: grid;
}

.pentagon::before, .triangle {
  background-image: linear-gradient(23deg, #ffeeff02 20%, #eeffff28, #ffe1, #efea 85%);
  background-size: 500% 500%;
  animation: shimmer 1s linear alternate infinite;
}

.pentagon::before {
  content: '';
  position: absolute;
  inset: 0;
  clip-path: polygon(
    calc(50%*(1 + sin(72deg*0))) calc(50%*(1 + cos(72deg*0))),
    calc(50%*(1 + sin(72deg*1))) calc(50%*(1 + cos(72deg*1))),
    calc(50%*(1 + sin(72deg*2))) calc(50%*(1 + cos(72deg*2))),
    calc(50%*(1 + sin(72deg*3))) calc(50%*(1 + cos(72deg*3))),
    calc(50%*(1 + sin(72deg*4))) calc(50%*(1 + cos(72deg*4))),

    calc(50%*(1 + cos(36deg)*sin(72deg*4.5))) calc(50%*(1 + cos(36deg)*cos(72deg*4.5))),
    calc(50%*(1 + cos(36deg)*sin(72deg*3.5))) calc(50%*(1 + cos(36deg)*cos(72deg*3.5))),
    calc(50%*(1 + cos(36deg)*sin(72deg*2.5))) calc(50%*(1 + cos(36deg)*cos(72deg*2.5))),
    calc(50%*(1 + cos(36deg)*sin(72deg*1.5))) calc(50%*(1 + cos(36deg)*cos(72deg*1.5))),
    calc(50%*(1 + cos(36deg)*sin(72deg*.5))) calc(50%*(1 + cos(36deg)*cos(72deg*.5))),

    calc(50%*(1 + cos(36deg)*sin(72deg*4.5))) calc(50%*(1 + cos(36deg)*cos(72deg*4.5)))
  );
  padding: 1px;
  animation-delay: calc(-.415s*var(--step));
  filter: hue-rotate(calc(var(--step)*61deg));
}

.side {
  transform: rotateY(calc(72deg*var(--step))) rotateX(calc(atan(.5) + 90deg - (var(--dir)*90deg))) translateZ(calc(var(--pushZ)*1em))
}

.lid {
  transform: rotateX(calc(90deg*var(--dir))) translateZ(calc(var(--pushZ)*1em)) rotate(36deg); 
}

.pentagon:nth-child(1),
.pentagon:nth-child(2) {
  --step: 0;
}

.pentagon:nth-child(3),
.pentagon:nth-child(4) {
  --step: 1;
}

.pentagon:nth-child(5),
.pentagon:nth-child(6) {
  --step: 2;
}

.pentagon:nth-child(7),
.pentagon:nth-child(8) {
  --step: 3;
}

.pentagon:nth-child(9),
.pentagon:nth-child(10) {
  --step: 4;
}

.pentagon:nth-child(11),
.pentagon:nth-child(12) {
  --step: 5;
}

.pentagon:nth-child(odd) {
  --dir: 1;
}

.pentagon:nth-child(even) {
  --dir: -1;
}

.triangle {
  top: 50%;
  justify-self: center;
  width: calc(cos(36deg)*sin(36deg)*var(--pentaW)*1em);
  --baseH: calc(cos(36deg)*cos(36deg)*var(--pentaW)*.5);
  --pyramidAngle: atan(.5);
  height: calc(1/sin(var(--pyramidAngle)) * var(--baseH)*.5em);
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
  transform-origin: 50% 0;
  transform: translateZ(calc(tan(var(--pyramidAngle))*var(--baseH)*1em)) rotate(calc(var(--triStep)*72deg)) rotateX(calc(-1*(var(--pyramidAngle))));
  animation-delay: calc(-.32s*var(--triStep) - .87s*var(--step));
  filter: hue-rotate(calc(var(--triStep)*43deg) + var(--step)*67deg);
  padding: 1px;
}

.triangle:nth-child(1) {
  --triStep: 0;
}

.triangle:nth-child(2) {
  --triStep: 1;
}

.triangle:nth-child(3) {
  --triStep: 2;
}

.triangle:nth-child(4) {
  --triStep: 3;
}

.triangle:nth-child(5) {
  --triStep: 4;
}

@keyframes shimmer {
  0% {
    background-position: top, left;
  }
 .........完整代码请登录后点击上方下载按钮下载查看

网友评论0