css 实现 div 翻转样式

 
更多

css 实现 div 翻转样式。

<html>
<head>
    <meta charset="UTF-8">
    <title>css 实现 div 翻转样式</title>
    <style>
        #container{text-align:center;width:100%;background-color:#ccc;}
        .box{
            width:300px;height:300px;text-align:center;background-color:#ffe4e4;margin:0 auto;
            position:relative;
            perspective:1000px;
            #loginBox, #registerBox{
                transform-style:preserve-3d;
                backface-visibility:hidden;
                transition-duration:.5s;
                transition-timing-function:'ease-in';
            }
            #registerBox{
                transform:rotateY(180deg);
                visibility:hidden;
                position:absolute;
                top:0;
                left:0;
                right:0;
                bottom:0;
            }
        }
        #loginBox{width:200px;height:300px;border-radius:4px;background-color:red;}
        #registerBox{width:200px;height:300px;border-radius:4px;background-color:blue;}
        .boxReverse{
            #loginBox{
                transform:rotateY(180deg);
                visibility:hidden;
            }
            #registerBox{
                transform:rotateY(360deg);
                visibility:visible;
            }
        }
    </style>
</head>
<body>
<div id="container">
    <div class="box" id="reverse">
        <div id="loginBox"><div>正面</div><button onclick="changeReverse()">去反面</button></div>
        <div id="registerBox"><div>反面</div><button onclick="changeReverse()">去正面</button></div>
    </div>
</div>
<script>
    let isRolling = false;
    function changeReverse() {
        isRolling = !isRolling;
        if (isRolling) {
            document.getElementById("reverse").className = "box boxReverse";
        } else {
            document.getElementById("reverse").className = "box";
        }
    }
</script>
</body>
</html>
打赏

本文固定链接: https://www.cxy163.net/archives/3007 | 绝缘体

该日志由 绝缘体.. 于 2024年01月28日 发表在 未分类 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: css 实现 div 翻转样式 | 绝缘体
关键字: , , , ,

css 实现 div 翻转样式:等您坐沙发呢!

发表评论


快捷键:Ctrl+Enter