3

I’m trying to change CSS Animation keyframes, it’s bouncing Y axis direction, but I’m trying to change it to X axis means trying to bounce left to right or right to left.

Fiddle: http://jsfiddle.net/5y8ebfcw/

HTML:

<div class='thisone'></div>

CSS:

.thisone {
-webkit-animation-name: slybounce;
-webkit-animation-duration: 3s;
-webkit-animation-timing-function: ease-in-out;
-webkit-animation-iteration-count: infinite;
-webkit-animation-delay: 0;
-webkit-animation-play-state: running;
-moz-animation-name: slybounce;
-moz-animation-duration: 3s;
-moz-animation-timing-function: ease-in-out;
-moz-animation-iteration-count: infinite;
-moz-animation-delay: 0;
-moz-animation-play-state: running;
}


@-webkit-keyframes slybounce {
  0% {
    -webkit-transform: translate(0, -5);
  }
  50% {
    -webkit-transform: translate(0, 5px);
  }
  100% {
    -webkit-transform: translate(0, -5);
  }
}

@-moz-keyframes slybounce {
  0% {
    -moz-transform: translate(0, -5);
  }
  50% {
    -moz-transform: translate(0, 5px);
  }
  100% {
    -moz-transform: translate(0, -5);
  }
}

I have tried this by changing translate(0, 5px); to translateX(0, 5px); Problem Fiddle: http://jsfiddle.net/5y8ebfcw/5/
But it’s not working. So my question is how to Animation bounce left to right or right to left.

Thanks.

2
  • can't you use .animate() method and animate it through margin-left property ? Maybe this fiddle will give you some idea Commented Apr 24, 2015 at 14:51
  • 1
    I guess you have got your answer :) Commented Apr 24, 2015 at 14:57

1 Answer 1

6

Invert the operands in translate(x,y), from translate(0,-5) / translate(0,+5) to translate(-5,0) / translate(+5,0).

Running demo

Or even better, use translateX instead of translate

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.