旋转立方体.html(网上收集5)

html 复制代码
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>旋转立方体</title>
    <style>
        #cube {
            width: 200px;
            height: 200px;
            position: relative;
            transform-style: preserve-3d;
            animation: rotate 6s infinite linear;
            margin: 100px auto;
        }

        #cube div {
            position: absolute;
            width: 200px;
            height: 200px;
            background-color: rgba(0, 255, 255, 0.5);
            border: 2px solid #333;
        }

        #cube .front {
            transform: translateZ(100px);
        }

        #cube .back {
            transform: rotateY(180deg) translateZ(100px);
        }

        #cube .right {
            transform: rotateY(90deg) translateZ(100px);
        }

        #cube .left {
            transform: rotateY(-90deg) translateZ(100px);
        }

        #cube .top {
            transform: rotateX(90deg) translateZ(100px);
        }

        #cube .bottom {
            transform: rotateX(-90deg) translateZ(100px);
        }

        @keyframes rotate {
            0% {
                transform: rotateX(0) rotateY(0) rotateZ(0);
            }
            100% {
                transform: rotateX(360deg) rotateY(360deg) rotateZ(360deg);
            }
        }
    </style>
</head>
<body>
<div id="cube">
    <div class="front"></div>
    <div class="back"></div>
    <div class="right"></div>
    <div class="left"></div>
    <div class="top"></div>
    <div class="bottom"></div>
</div>
<script>
    const cube = document.querySelector('#cube');
    let isPaused = false;

    cube.addEventListener('mouseover', () => {
        isPaused = true;
        cube.style.animationPlayState = 'paused';
    });

    cube.addEventListener('mouseout', () => {
        isPaused = false;
        cube.style.animationPlayState = 'running';
    });

    setInterval(() => {
        if (!isPaused) {
            cube.style.animationPlayState = 'running';
        }
    }, 1000);
</script>
</body>
</html>
相关推荐
在逃花果山的小松15 小时前
CSS 调试头大报错难查?ChatGPT 一键定位样式问题并给出修复方案
css
gz-郭小敏16 小时前
优化横向滚动展示大量数据的时候数据晃动问题
前端·javascript·html·css3
IMPYLH17 小时前
HTML 的 <a>元素
前端·javascript·html
AI行业学习19 小时前
CC‑Switch v3.16.1 免费下载(Windows+macOS+Linux)、使用方法【2026.6.11】
linux·开发语言·windows·python·macos·前端框架·html
编程技术手记20 小时前
Vue Scoped CSS 与动态创建 DOM 的兼容性问题
前端·css·vue.js
用户0595401744621 小时前
LangChain 记忆模块踩坑实录:靠自动化测试,我把上下文丢失率从 30% 降到 0
前端·css
elirlove121 小时前
打造属于自己的网页工匠台:HTML在线编辑器技术深度解析
前端·编辑器·html
qq_363066931 天前
react 使用web component导出静态html报告
前端·react.js·html·页面导出
weixin_457763081 天前
展示youtube的视频
前端·javascript·html
雨翼轻尘1 天前
03_HTML进阶标签与CSS入门
前端·css·html·入门·进阶标签