繁体   English   中英

透视CSS3无法正常工作

[英]Perspective CSS3 Not Working

我正在尝试在X轴方向上开发卡片翻转动画。 截至目前, div现在仅使用rotateX()方法进行旋转。 我尝试对上层div使用Perspective属性,而不是对其进行操作会扭曲我的div结构。 因为这只是一个工作阶段,所以我只针对Google chrome。 请在codepen上看到它。

这是我的HTML代码。

<div class="wrapper">
                <div class="upper">
                    <div class="upper-current">
                        <div class="content">
                            1
                        </div>
                    </div>
                    <div class="upper-next">
                        <div class="content">
                            2
                        </div>
                    </div>
                </div>

                <div class="lower">
                    <div class="lower-current">
                        <div class="content">
                            1
                        </div>
                    </div>
                    <div class="lower-next">
                        <div class="content">
                            2
                        </div>
                    </div>
                </div>
            </div>

还有我的CSS,div.row {width:150px; 高度:200px; 保证金:0自动; }

        div.wrapper{
            background-color: #444;
            width: 150px;
            height: 200px;
            border-radius: 5px;
            position:relative;

        }

        div.wrapper div.upper, div.wrapper div.lower{
            height: 100px;
            width:100%;

        }

        div.upper-current{
            transition :all 1s;
            transform-origin: 50% 100%;
        }

        div.wrapper > div.upper > div, div.wrapper > div.lower > div{
            height: 100px;
            width:100%;
            position:absolute;
            top:0;
            overflow:hidden;
            text-align:center;
            background-color:#444;
        }

        div.wrapper > div.upper > div{
            border-bottom: 3px solid #333;
        }

        div.wrapper > div.lower > div{
            height: 200px;
        }

        div.upper-current{
            z-index: 4;
        }

        div.upper-next{
            z-index: 3;
        }

        div.lower-current{
            z-index: 2;
        }

        div.lower-next{
            z-index: 1;
        }

        div.content{
            position: relative;
            top: -24px;
        }

我正在努力达到这种效果。 顶部边缘较大,看起来像出来。

但是用我的代码,我简直就是傻瓜。 普通旋转效果。

更新:代码笔也应在firefox上工作。 由于堆栈上下文问题,我只是将.upper relative ,并为其指定了z-index,使其位于.lower

如果将perspective CSS属性放在.wrapper它应该可以工作: codepen

Perspective创建了一个新的堆栈上下文,因此,如果将其放在.upper ,由于自然的HTML,所有上面的<div> z-index不再与下面的上下文在同一上下文中,而下面的z-index在上面堆叠。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM