css实现立体骰子

css3 使用animation,transiform实现滚动骰子

css骰子

css 复制代码
    <style>
        .test {
            width: 80px;
            height: 80px;
            position: relative;
            transform-style: preserve-3d;
            animation: move 2s linear 0s infinite alternate;
        }
        .up,
        .down,
        .left,
        .right,
        .forwards,
        .back {
            width: 100%;
            height: 100%;
            display: grid;
            align-content: space-evenly;
            justify-items: center;
            position: absolute;
            font-size: 40px;
            border-radius: 20px;
            border: 2px solid gray;
            background-color: #fff;
        }
        .up {
            transform: rotateX(90deg) translateZ(50px);
        }
        .down {
            transform: rotateX(-90deg) translateZ(50px);
            grid-template-columns: repeat(3, 1fr);
        }
        .left {
            transform: rotateY(90deg) translateZ(50px);
        }
        .right {
            transform: rotateY(-90deg) translateZ(50px);
            grid-template-columns: repeat(2,1fr);
        }
        .forwards {
            transform: translateZ(50px);
        }
        .back {
            transform: translateZ(-50px);
            grid-template-columns: repeat(3, 1fr);
            grid-template-rows: repeat(2, 1fr);
            align-items: center;
        }
        .up .item,
        .forwards .item:nth-child(2) {
            background-color: red;
        }
        .back .item:nth-child(3){
            grid-area: 1/2/3/3 ;
            
            background-color: red;
        }
        @keyframes move {
            0% {
                transform: rotateX(-90deg) rotateY(-90deg);
            }
            25% {
                transform: rotateX(0deg) rotateY(0deg);
            }
            50% {
                transform: rotateX(90deg) rotateY(90deg);
            }
            75% {
                transform: rotateX(180deg) rotateY(180deg);
            }
            100% {
                transform: rotateX(360deg) rotateY(360deg);
            }
        }
        .item {
            width: 20px;
            height: 20px;
            background-color: black;
            border-radius: 50%;
        }
    </style>
<body>
    <div class="test">
        <div class="up">
            <span class="item"></span>
        </div>
        <div class="down">
            <span class="item"></span>
            <span class="item"></span>
            <span class="item"></span>
            <span class="item"></span>
            <span class="item"></span>
            <span class="item"></span>
        </div>
        <div class="left">
            <span class="item"></span>
            <span class="item"></span>
        </div>
        <div class="right">
            <span class="item"></span>
            <span class="item"></span>
            <span class="item"></span>
            <span class="item"></span>
        </div>
        <div class="forwards">
            <span class="item"></span>
            <span class="item"></span>
            <span class="item"></span>
        </div>
        <div class="back">
            <span class="item"></span>
            <span class="item"></span>
            <span class="item"></span>
            <span class="item"></span>
            <span class="item"></span>
        </div>
    </div>
</body>
相关推荐
Z***258013 分钟前
JavaScript在Node.js中的Deno
开发语言·javascript·node.js
cypking44 分钟前
Vue 3 + Vite + Router + Pinia + Element Plus + Monorepo + qiankun 构建企业级中后台前端框架
前端·javascript·vue.js
San30.1 小时前
ES6+ 新特性解析:让 JavaScript 开发更优雅高效
开发语言·javascript·es6
u***27612 小时前
TypeScript 与后端开发Node.js
javascript·typescript·node.js
星空的资源小屋2 小时前
跨平台下载神器ArrowDL,一网打尽所有资源
javascript·笔记·django
Dorcas_FE3 小时前
【tips】动态el-form-item中校验的注意点
前端·javascript·vue.js
八月ouc3 小时前
解密JavaScript模块化演进:从IIFE到ES Module,深入理解现代前端工程化基石
javascript·es6·模块化·cmd·commonjs·amd·iife
四岁爱上了她3 小时前
input输入框焦点的获取和隐藏div,一个自定义的下拉选择
前端·javascript·vue.js
烟袅4 小时前
5 分钟把 Coze 智能体嵌入网页:原生 JS + Vite 极简方案
前端·javascript·llm
神秘的猪头4 小时前
🧠 深入理解 JavaScript Promise 与 `Promise.all`:从原型链到异步编程实战
前端·javascript·面试