简体   繁体   English

使css3过渡始终沿相同方向旋转

[英]make css3 transition rotate always in the same direction

I am trying to have a front-/backside div flipping always in the same direction. 我正在尝试使前/后div始终沿相同方向翻转。 I implemented the flip with css and javascript, but I have a hard time thinking about how to make it always rotate to the right, instead of rotate to the right and then coming back to the left. 我使用css和javascript实现了翻页功能,但是我很难考虑如何使其始终向右旋转,而不是向右旋转然后回到左侧。

I basically use a div with the follwing css 我基本上将div与以下CSS一起使用

  /* flip speed goes here */
  .flipper {
    -webkit-transition: 0.6s;
    -webkit-transform-style: preserve-3d;

    -moz-transition: 0.6s;
    -moz-transform-style: preserve-3d;

    -o-transition: 0.6s;
    -o-transform-style: preserve-3d;

    transition: 0.6s;
    transform-style: preserve-3d;

    position: relative;
    border-radius: 5px;
  -webkit-border-radius: 5px;
    padding: 5px;
    margin-left: 3px;
    z-index: 3;
    width: 160px;
    height: 145px;
    display:block; 
  }

and when the user clicks on it I add the class "flipped" to the div which changes the css to this: 当用户单击它时,我将“ flipped”类添加到div中,从而将css更改为:

      /* flip the pane when hovered */
  .flip-container.flipped .flipper {
    -webkit-transform: rotateY(180deg);
    -moz-transform: rotateY(180deg);
    -o-transform: rotateY(180deg);
    transform: rotateY(180deg);
  }

should I just increment always the rotation angle? 我应该一直增加旋转角度吗? any other ideas? 还有其他想法吗?

Here is the current status and the full css in a fiddle 这是当前状态和小提琴中的完整CSS

I don't think that it can be done with transforms. 我不认为可以通过转换来完成。 May be you can do it with keyframes. 也许您可以使用关键帧来做到这一点。 A similar code: 类似的代码:

@-webkit-keyframes rotate1 {
    from {-webkit-transform: rotate(0deg)}
    to {-webkit-transform: rotate(180deg)}
}
@-webkit-keyframes rotate2 {
    from {-webkit-transform: rotate(180deg)}
    to {-webkit-transform: rotate(360deg)}
}

#rotable {
    background-color: red;
    -webkit-animation-name: rotate2;
    -webkit-animation-duration: 3s;
    -webkit-transform: rotate(180deg); 
}

#rotable:hover {
    background-color: yellow;
    -webkit-animation-name: rotate1;
    -webkit-animation-duration: 3s;
}

does a similar thing to what you want. 做与您想要的类似的事情。 Notice that the turning direction is always the same. 请注意,转弯方向始终相同。

Another posibility, mixing transition and animation (for the change where the transition would go in the opposite direction ...) 另一个可能性,混合过渡和动画(用于过渡沿相反方向的更改...)

 .container { perspective: 500px; } .test { transform: rotate(360deg); transition: transform 4s; } .container:hover .test { transform: rotateY(180deg); animation: turn 4s; } @keyframes turn { from {transform: rotate(0deg);} } div { display: inline-block; width: 200px; height: 200px; } .test { background-color: lightblue; } 
 <div class="container"> <div class="test">TEST</div> </div> 

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

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