Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make css3 transition rotate always in the same direction

I am trying to have a front-/backside div flipping always in the same direction. 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.

I basically use a div with the follwing 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:

      /* 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

like image 478
tmaximini Avatar asked Jan 08 '13 16:01

tmaximini


People also ask

How do you make something rotate infinitely in CSS?

To create an endless rotation animation simply define a @keyframe with any name and from and to values. Then you can use this @keyframe in your animation in any CSS class.

Which css3 property will allow you to rotate an object?

The transform property applies a 2D or 3D transformation to an element. This property allows you to rotate, scale, move, skew, etc., elements.

How do you rotate an object 90 degrees counterclockwise CSS?

We can add the following to a particular tag in CSS: -webkit-transform: rotate(90deg); -moz-transform: rotate(90deg); -o-transform: rotate(90deg); -ms-transform: rotate(90deg); transform: rotate(90deg); In case of half rotation change 90 to 45 .

How do you rotate objects using css3?

CSS rotate() The rotate() function accepts one argument: the angle at which you want to rotate your web element. You can rotate an element clockwise or counter-clockwise. Let's take a look at the syntax for the rotate() function: transform: rotate(angle);


1 Answers

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>
like image 148
vals Avatar answered Sep 29 '22 21:09

vals