HTML5 3D立方体翻转动画特效

<!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>

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值