简体   繁体   English

CSS3有关变换动画的问题

[英]CSS3 Issue about transform animation

I am learning CSS3 features these days. 我最近正在学习CSS3功能。 I try to implement an effect of card flipping . 我尝试实现翻牌的效果。 (jsfiddle) (的jsfiddle)

Here is the code. 这是代码。

html, body{
    margin: 0;
    padding: 0;
    background-color: #ccc;
}

.container{
    position: relative;
    width: 300px;
    height: 500px;
    margin: 5% auto;
    perspective: 500px;
}

#card{
    width: 100%;
    height: 100%;
    background-color: #567890;
    -webkit-animation: flip 1s;
    transform-style: preserve-3d;
    position: relative;
}

@-webkit-keyframes flip{
    0% { transform: rotateY(0deg); }
    100% { transform: rotateY(180deg); }
}

.front, .back{
    position: absolute;
    backface-visibility: hidden;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
}

#card .front {
  background: red;
}
#card .back {
  background: blue;
  transform: rotateY( 180deg );
}

And HTML. 和HTML。

<div class="container">
    <div id="card">
        <figure class="front">1</figure>
        <figure class="back">2</figure>
    </div>
/div>

Here are the problems. 这里有问题。

  1. The div has two sides, front and back. div具有正面和背面两个侧面。 The transition should be from front side to back side. 过渡应该是从正面到背面。 But in this program, front side returns. 但是在该程序中,前端返回。

  2. Front side and back side's position are not right. 正面和背面的位置不正确。 They should be inside the div card. 它们应该在div卡中。

Can someone help me? 有人能帮我吗? Many thanks! 非常感谢!

instead of rotating you .card why don't you rotate the front and back div vice versa 而不是旋转.card为什么不rotate frontback div反之亦然

JS Fiddle JS小提琴

added keyframes for front and back div to rotate 对于添加关键帧frontback的div旋转

@-webkit-keyframes front {
    0% {
        transform: rotateY(0deg);
    }
    100% {
        transform: rotateY(180deg);
    }
}
@-webkit-keyframes back {
    0% {
        transform: rotateY(-180deg);
    }
    100% {
        transform: rotateY(0deg);
    }
}

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

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