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>
相关推荐
x原力觉醒1 小时前
uniapp跨域问题,在开发环境中配置
javascript·vue.js·uni-app
理想不理想v1 小时前
【问答】浏览器如何编译前端代码?
前端·javascript·css·html
王哲晓1 小时前
第十五章 Vue工程化开发及Vue CLI脚手架
前端·javascript·vue.js
揽月凡尘1 小时前
typescript webpack 库打包发布
javascript·webpack·typescript
爱编程的小金1 小时前
React-query vs. 神秘新工具:前端开发的新较量
前端·javascript·react.js·http·前端javascript
qq_427506081 小时前
react轮播图示例
前端·javascript·react.js
江-月*夜2 小时前
uniapp vuex 搭建
android·javascript·uni-app
啊QQQQQ3 小时前
linux:回车换行+进度条+git理解与使用以及如何解决免密码push问题
开发语言·javascript·ecmascript
熊的猫3 小时前
如何封装一个可取消的 HTTP 请求?
前端·javascript·vue.js·网络协议·http·webpack·node.js