3

I am not sure why the transform: translateX is not working on my animation. I am trying to move a div 100px and then backwards to the starting spot.

Here is a fiddle: http://jsfiddle.net/tWnRb/

Here is my HTML:

<div></div>

Here is my CSS:

div {
  width: 200px;
  height: 200px;
  background: coral;
  -webkit-animation: squareToCircle 2s 1s infinite alternate;

}

-webkit-keyframes squareToCircle {
  0% {
    border-radius: 0 0 0 0;
    background: coral;
    -webkit-transform: translateX(0px);
  }
  25% {
    border-radius: 50% 0 0 0;
    background: darksalmon;
    -webkit-transform: translateX(50px);
  }
  50% {
    border-radius: 50% 50% 0 0;
    background: hotpink;
    -webkit-transform: translateX(100px);
  }
  75% {
    border-radius: 50% 50% 50% 0;
    background: lightcoral;
    -webkit-transform: translateX(50px);
  }
  100% {
    border-radius: 50% 50% 50% 50%;
    background: darksalmon;
    -webkit-transform: translateX(0px);
  }
}
1

2 Answers 2

3

keyframes need to be prefixed with @

DEMO

@-webkit-keyframes NAME-YOUR-ANIMATION { }
@-moz-keyframes NAME-YOUR-ANIMATION { }
@-o-keyframes NAME-YOUR-ANIMATION { }
@keyframes NAME-YOUR-ANIMATION { }

You also should accomodate other browsers as well as webkit.

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

2 Comments

Thank you! I did not realize it needed the @
Thanks again! I will add the vendor prefixes, I just left them off to make the example code easier to debug :)
1

http://jsfiddle.net/tWnRb/5/

-webkit-keyframes squareToCircle {

to

@-webkit-keyframes squareToCircle {

2 Comments

Thanks! I did not realize the @ was needed! Small syntax errors always seem to get me when i'm tyring to learn something new. Thanks again!
go with Obsidion's answer - his is more complete

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.