旋转立方体.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>
相关推荐
拜无忧2 小时前
html,svg,花海扩散效果
前端·css·svg
华仔啊6 小时前
Vue3+CSS 实现的 3D 卡片动画,让你的网页瞬间高大上
前端·css
在云端易逍遥8 小时前
前端必学的 CSS Grid 布局体系
前端·css
进阶的鱼8 小时前
(4种场景)单行、多行文本超出省略号隐藏
前端·css·面试
石金龙1 天前
[译] Composition in CSS
前端·css
天天扭码1 天前
来全面地review一下Flex布局(面试可用)
前端·css·面试
用户458203153171 天前
CSS特异性:如何精准控制样式而不失控?
前端·css
葡萄城技术团队1 天前
所有网站通用:6 行 HTML 代码搞定页面加载提速
html
糖糖TANG1 天前
从零开始制作我的第一个静态网页——教师节主题首页开发记录
html
会豪1 天前
CSS 动画属性精讲:从基础到实战
前端·css