css+gsap实现三维魔方旋转动画效果代码

代码语言:html

所属分类:三维

代码描述:css+gsap实现三维魔方旋转动画效果代码

代码标签: 魔方 旋转 动画 效果

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


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

<head>

  <meta charset="UTF-8">

  
<style>
body {
  display: grid;
  place-content: center;
  width: 100%;
  height: 100vh;
  overflow: hidden;
}

.credits {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  text-align: center;
}

.hero {
  --cube-size: 240px;
}
@media only screen and (max-width: 560px) {
  .hero {
    --cube-size: 180px;
  }
}

.env {
  height: var(--cube-size);
  width: var(--cube-size);
  position: relative;
  transform-style: preserve-3d;
  transform: rotate(35.264deg) rotateY(-30deg) rotateX(35.264deg);
}

.shadow {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  background: #000;
  border-radius: 1.25%;
  opacity: 0.25;
  filter: blur(calc(var(--cube-size) * .1));
  transform: translateZ(calc(var(--cube-size) * -1)) scale(0.95);
  will-change: transform;
  transform-style: preserve-3d;
}

.cube {
  width: 100%;
  height: 100%;
  position: relative;
  transform: rotate(-90deg) rotateX(-90deg);
  transform-style: preserve-3d;
}

.face {
  position: absolute;
  width: 100%;
  height: 100%;
  background: #333;
  font-size: 30px;
  top: 0;
  left: 0;
  backface-visibility: hidden;
  color: #333;
  box-shadow: 0 0 1px 0.5px currentColor;
}
.face--1 {
  transform: translateY(calc(var(--cube-size) * -.5)) rotateX(90deg);
}
.face--2 {
  transform: translateZ(calc(var(--cube-size) * .5));
}
.face--3 {
  transform: translateY(calc(var(--cube-size) * .5)) rotateX(-90deg);
}
.face--4 {
  transform: translateZ(calc(var(--cube-size) * -.5)) rotateX(180deg);
}
.face--5 {
  transform: translateX(calc(var(--cube-size) * -.5)) rotateY(-90deg);
}
.face--6 {
  transform: translateX(calc(var(--cube-size) * .5)) rotateY(90deg);
}
.face img, .face svg {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
}
</style>




</head>

<body >
  <section class="hero">
  <div class="env">
    <div class="shadow"></div>
    <div class="cube">
      <div class="face face--1">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1600 1600">
          <defs/>
          <g fill="none" fill-rule="nonzero">
            <path fill="#402640" d="M0 0v1600h300v-100h1000v100h300V0H0zm400 1400H300v-100h100v100zm200 0H500v-100h100v100zm300 0H700v-100h200v100zm200 0h-100v-100h100v100zm200 0h-100v-100h100v100zm200 100h-100v-300H200v300H100V100h1400v1400z"/>
            <path fill="#FDE04B" d="M1600 1600v-100h-100v100z"/>
            <path fill="#988631" d="M1515 1515h70v25h-45v20h20v-15h25v40h-70z"/>
            <path fill="#8B5F90" d="M600 1100H200V800H100v700h100v-300h400z"/>
            <path fill="#402640" d="M200 300v800h500V300H200zm400 700H300V400h300v600z"/>
            <path fill="#DF2564" d="M300 400h300v200H300z"/>
            <path fill="#333332" d="M300 600h100v200H300z"/>
            <path fill="#F7EF3C" d="M400 600v200H300v100h300V600z"/>
            <path fill="#FAC43D" d="M600 1000H300V900h300z"/>
            <path fill="#F8EACC" d="M300 1300h100v100H300zM500 1300h100v100H500z"/>
            <path fill="#8B5F90" d="M200 200h500v100H200zM1000 1100h400V800h100v700h-100v-300h-400z"/>
            <path fill="#AC75B3" d="M100 100v700h100V200h500v900H600v99h400v-99H900V200h500v600h100V100z"/>
            <path fill="#402640" d="M900 300v800h500V300H900zm100 100h300v600h-300V400z"/>
            <path fill="#DF2564" d="M1000 400h300v200h-300z"/>
            <path fill="#333332" d="M1200 600h100v200h-100z"/>
            <path fill="#F7EF3C" d="M1200 600v200h100v100h-300V600z"/>
            <path fill="#FAC43D" d="M1000 1000h300V900h-300z"/>
            <path fill="#F8EACC" d="M1200 1300h100v100h-100zM1000 1300h100v100h-100z"/>
            <path fill="#8B5F90" d="M900 200h500v100H900z"/>
            <path fill="#F8EACC" d="M700 1300h200v100H700z"/>
            <path fill="#9C7F9C" d="M300 1500h1000v100H300z"/>
          </g>
        </svg>
      </div>
      <div class="face face--2">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1600 1600">
          <defs/>
          <g fill="none" fill-rule="nonzero">
            <path fill="#46162F" d="M1599 0H0v1600h1600L1599 0zM100 1500V100h1400v1400H100z"/>
            <path fill="#FDE04B" d="M1600 1600v-100h-100v100z"/>
            <path fill="#988631" d="M1515 1515h70v25h-45v20h20v-15h25v40h-70z"/>
            <path fill="#F06BA8" d="M100 100h1400v100H100z"/>
            <path fill="#D2237E" d="M200 1099h500v101H200zM900 1099h500v101H900z"/>
            <path fill="#46162F" d="M200 400h500v100H200z"/>
            <path fill="#DD2785" d="M500 500h100v200H500z"/>
            <path fill="#751747" d="M300 1300h200v200H300zM1100 1300h200v200h-200zM700 1300h200v200H700zM600 500v500H300V500H200v600h500V500z"/>
            <path fill="#F6EE3E" d="M500 700V500H300v400h300V700z"/>
            <path fill="#FAC43D" d="M300 900h300v100H300z"/>
            <path fill="#46162F" d="M900 400h500v100H900z"/>
            <path fill="#DD2785" d="M1000 500h100v200h-100z"/>
            <path fill="#751747" d="M1300 500v500h-300V500H900v600h500V500z"/>
            <path fill="#F6EE3E" d="M1100 700V500h200v400h-300V700z"/>
            <path fill="#FAC43D" d="M1000 900h300v100h-300z"/>
            <path fill="#EE3696" d="M100 200v1300h200v-200h200v200h200v-200h200v200h200v-200h200v200h200V200H100zm600 999H200V400h500v799zm700 0H900V400h500v799z"/>
          </g>
        </svg>
      </div>
      <div class="face face--3">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1600 1600">
          <defs/>
          <g fill="none" fill-rule="nonzero">
            <path fill="#502F2B" d="M0 0v1600h500v-200h600v200h500V0H0zm1500 1500h-300v-200H400v200H100V100h1400v1400z"/>
            <path fill="#3F4040" d="M1000 600h100v100h-100z"/>
            <path fill="#7B3418" d="M700 900V200H200v700h500zM300 300h300v500H300V300z"/>
            <path fill="#FAA41A" d="M100 100v100h600v700H500v100h600V900H900V200h600V100H100z"/>
            <path fill="#DD8A27" d="M1000 300h300v300h-300z"/>
            <path fill="#3F4040" d="M500 700h100V500H500v200z"/>
            <path fill="#DD8A27" d="M1400 200v700h-300v100h400V200zM200 900V200H100v800h400V900z"/>
            <path fill="#F5EDB8" d="M500 500H300v300h300V700H500zM1100 600v100h-100v100h300V600z"/>
            <path fill="#FCC66C" d="M300 1100h1000v100H300z"/>
            <path fill="#7B3418" d="M200 1000v300h100v-200h1000v200h100v-300z"/>
            <path fill="#FDE04B" d="M1600 1600v-100h-100v100z"/>
            <path fill="#988631" d="M1515 1515h70v25h-45v20h20v-15h25v40h-70z"/>
            <path fill="#BF9C64" d="M500 1400v200h600v-200z"/>
            <pat.........完整代码请登录后点击上方下载按钮下载查看

网友评论0