div+css实现三维锥子旋转交互动画效果代码

代码语言:html

所属分类:动画

代码描述:div+css实现三维锥子旋转交互动画效果代码

代码标签: div css 三维 锥子 旋转 交互 动画

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

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

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

  
  
  
<style>
@import url("https://fonts.googleapis.com/css2?family=Rubik+Moonrocks&display=swap");
*, *::before, *::after {
  padding: 0;
  margin: 0 auto;
  box-sizing: border-box;
}

body {
  font-family: "Rubik Moonrocks", sans-serif;
  background-color: skyblue;
  min-height: 100vh;
  display: grid;
  place-items: center;
  perspective: 800px;
  font-size: 10px;
}
body *:not(:empty) {
  transform-style: preserve-3d;
}

.scene {
  position: relative;
  transform: translateY(15em) rotateY(calc(60deg * var(--x, 0) - 30deg)) rotateX(calc(40deg * var(--y, 0) - 30deg));
}

.floor {
  position: absolute;
  inset: -100em;
  transform: rotateX(90deg);
  background-color: #fff;
  transform-style: preserve-3d;
  background-image: radial-gradient(closest-side, transparent, skyblue), repeating-linear-gradient(0deg, #0001 0 2px, transparent 4px calc(3em - 4px), #0001 calc(3em - 2px) 1em), repeating-linear-gradient(60deg, #0001 0 2px, transparent 4px calc(3em - 4px), #0001 calc(3em - 2px) 1em), repeating-linear-gradient(120deg, #0001 0 2px, transparent 4px calc(3em - 4px), #0001 calc(3em - 2px) 1em);
}
.floor::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: radial-gradient(closest-side, white, transparent);
  transform-origin: top;
  transform: rotateX(90deg) scale(5, 2);
}
.floor::after {
  content: "";
  position: absolute;
  left: calc(50% - 10em);
  top: calc(50% - 10em);
  width: 20em;
  height: 20em;
  background-image: radial-gradient(closest-side, #000a, 10%, #0000);
  -webkit-animation: shadowY 3s infinite ease-in-out alternate, moveTranslate 4s infinite ease-in-out alternate;
          animation: shadowY 3s infinite ease-in-out alternate, moveTranslate 4s infinite ease-in-out alternate;
}
@-webkit-keyframes shadowY {
  0% {
    transform: translateY(15em);
  }
  100% {
    transform: translateY(-15em);
  }
}
@keyframes shadowY {
  0% {
    transform: translateY(15em);
  }
  100% {
    transform: translateY(-15em);
  }
}

.moveX {
  position: absolute;
  -webkit-animation: moveTranslate 3s infinite ease-in-out alternate, moveRotate 3s -4.5s infinite ease-in-out alternate;
          animation: moveTranslate 3s infinite ease-in-out alternate, moveRotate 3s -4.5s infinite ease-in-out alternate;
}

.moveY {
  position: absolute;
  transform: rotateY(90deg);
  -webkit-animation: moveTranslate 4s infinite ease-in-out alternate, moveRotate 4s -6s infinite ease-in-out alternate;
          animation: moveTranslate 4s infinite ease-in-out alternate, moveRotate 4s -6s infinite ease-in-out alternate;
}

@-webkit-keyframes moveTranslate {
  0% {
    translate: -15em;
  }
  100% {
    translate: 15em;
  }
}

@keyframes moveTranslate {
  0% {
    translate: -15em;
  }
  100% {
    translate: 15em;
  }
}
@-webkit-keyframes moveRotate {
  0% {
    rotate: 15deg;
  }
  100% {
    rotate: -15deg;
  }
}
@keyframes moveRotate {
  0% {
    rotate: 15deg;
  }
  100% {
    rotate: -15deg;
  }
}
.dreidel {
  position: absolute;
  -webkit-animation: dRotate 1s infinite linear;
          animation: dRotate 1s infinite linear;
  --rrg: transparent 0, #0001, transparent 0.6em;
}
@-webkit-keyframes dRotate {
  to {
    rotate: y 1turn;
  }
}
@keyframes dRotate {
  t.........完整代码请登录后点击上方下载按钮下载查看

网友评论0