0

I am trying to have a block of DIV to move to the right by 300px, THEN rotate about the Y axis by 180deg, move back to the origin X position, then rotate about the Y axis by 180deg.

 |-->---->----->------|
rotate             rotate
 |----<-----<-----<---|

What I have now rotates and moves at the same time. Is there any way I can define these transformations step by step?

http://jsbin.com/nomuqe/edit?html,css,output

Thank you!

1 Answer 1

1

You need to set more keyframes with the required values.

Since you want to make the rotation keeping the same position (translation), you need to set 2 keyframes with the same translate value and changing only the rotation

.test{
  display: block;
  width: 50px;
  height: 50px;
  border-radius: 20px 0 0px 20px;
  background: orange; 
  animation: move 4s infinite;
}
@keyframes move{
  0%{
    transform: translateX(0px)  rotateY(0deg);
  }
  49%{
    transform: translateX(300px) rotateY(0deg);
  }
  50%{
    transform: translateX(300px) rotateY(180deg);
  }
  100%{
    transform: translateX(0px) rotateY(180deg);
  }
}
  <div class='test'></div>

Sign up to request clarification or add additional context in comments.

2 Comments

Hi Vals! Thanks for the quite answer! Can you explain also why both 49 and 50% have the translateX(300px?)
Added more detail in the answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.