旋转立方体.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 小时前
Day 2|CSS 盒模型:把昨天的骨架,变成能看的页面
前端·css
keyipatience3 小时前
JS学习笔记(2)数组,函数,作用域,对象
前端·javascript·笔记·学习·html
oicola4 小时前
Ant Design v5 vs Tailwind CSS:组件库与样式框架的终极对决
前端·css
java1234_小锋6 小时前
【技术专题】HTML5 网页技术 - HTML5 列表标签
前端·html·html5
data analyse 4569 小时前
前端白屏问题按路由和资源加载顺序定位
大数据·前端·人工智能·数据分析·html
软件技术NINI18 小时前
美妆商城html+Css+js 4页
javascript·css·html
2603_965896621 天前
Grid 网格布局|CSS 二维页面排版体系
前端·css
多喝水身体棒1 天前
# CSS Grid布局入门,二维布局再也不用float了
css
软件技术NINI1 天前
化妆品html+css+js 7页
javascript·css·html
kaixin_learn_qt_ing1 天前
hexdump -C /path/to/binary | less 看十六进制内容
前端·css·less