<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML5 3D立方体翻转动画特效</title>
<style>
body {
margin: 0;
padding: 0;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background: linear-gradient(135deg, #1a1a2e, #16213e);
overflow: hidden;
perspective: 1000px;
}
.scene {
width: 300px;
height: 300px;
position: relative;
transform-style: preserve-3d;
animation: rotate 15s infinite linear;
}
.cube {
width: 100%;
height: 100%;
position: relative;
transform-style: preserve-3d;
animation: rotate-inner 8s infinite linear reverse;
}
.face {
position: absolute;
width: 100%;
height: 100%;
border: 3px solid rgba(255, 255, 255, 0.2);
box-shadow: 0 0 30px rgba(0, 255, 255, 0.5);
display: flex;
justify-content: center;
align-items: center;
font-size: 40px;
font-weight: bold;
color: white;
opacity: 0.9;
transition: all 0.5s ease;
}
.face:hover {
opacity: 1;
box-shadow: 0 0 40px rgba(0, 255, 255, 0.8);
}
.front {
background: rgba(255, 0, 0, 0.7);
transform: translateZ(150px);
}
.back {
background: rgba(0, 255, 0, 0.7);
transform: rotateY(180deg) translateZ(150px);
}
.right {
background: rgba(0, 0, 255, 0.7);
transform: rotateY(90deg) translateZ(150px);
}
.left {
background: rgba(255, 255, 0, 0.7);
transform: rotateY(-90deg) translateZ(150px);
}
.top {
background: rgba(255, 0, 255, 0.7);
transform: rotateX(90deg) translateZ(150px);
}
.bottom {
background: rgba(0, 255, 255, 0.7);
transform: rotateX(-90deg) translateZ(150px);
}
@keyframes rotate {
0% {
transform: rotateX(0) rotateY(0);
}
100% {
transform: rotateX(360deg) rotateY(360deg);
}
}
@keyframes rotate-inner {
0% {
transform: rotateX(0) rotateY(0);
}
100% {
transform: rotateX(-360deg) rotateY(-360deg);
}
}
.info {
position: absolute;
bottom: 30px;
left: 0;
width: 100%;
text-align: center;
color: rgba(255, 255, 255, 0.5);
font-family: Arial, sans-serif;
font-size: 14px;
}
/* 粒子背景效果 */
.particles {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
}
.particle {
position: absolute;
background: rgba(255, 255, 255, 0.5);
border-radius: 50%;
animation: float linear infinite;
}
@keyframes float {
to {
transform: translateY(-100vh);
}
}
</style>
</head>
<body>
<div class="scene">
<div class="cube">
<div class="face front">1</div>
<div class="face back">2</div>
<div class="face right">3</div>
<div class="face left">4</div>
<div class="face top">5</div>
<div class="face bottom">6</div>
</div>
</div>
<div class="particles" id="particles"></div>
<script>
// 创建粒子背景
const particlesContainer = document.getElementById('particles');
const particleCount = 50;
for (let i = 0; i < particleCount; i++) {
const particle = document.createElement('div');
particle.classList.add('particle');
// 随机大小
const size = Math.random() * 5 + 1;
particle.style.width = `${size}px`;
particle.style.height = `${size}px`;
// 随机位置
particle.style.left = `${Math.random() * 100}%`;
particle.style.top = `${Math.random() * 100}%`;
// 随机透明度
particle.style.opacity = Math.random() * 0.5 + 0.1;
// 随机动画持续时间
const duration = Math.random() * 20 + 10;
particle.style.animationDuration = `${duration}s`;
// 随机延迟
particle.style.animationDelay = `${Math.random() * 10}s`;
particlesContainer.appendChild(particle);
}
</script>
</body>
</html>
HTML5 3D立方体翻转动画特效
于 2025-06-14 13:10:52 首次发布
980

被折叠的 条评论
为什么被折叠?



