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"/>
.........完整代码请登录后点击上方下载按钮下载查看
网友评论0