How to animate a ball along a curved path using css3 animation?

I have this script to animate a ball along a curved path. I do not know how to implement this using css3. I know that there is no type animation path.

Is there a way to animate a ball on a curved background.

here is live demo

my code is:

div.path {
  background:url(https://dl.dropboxusercontent.com/u/10268257/images/path.png) no-repeat center bottom;
  width:397px;
  height:66px;
  position: relative;
}

div.ball {
  background : green;
  width:20px; height:20px;
  border-radius:50%;
}
<div class="container">
  <div class="path">
    <div class="ball"></div>
  </div>
</div>
Run code
+4
source share
1 answer

This is not a complete solution to your Question, but you asked how I can define pathcss in the animation, so you can:

JSFIDDLE

div.ball {
    background : green;
    width:20px; height:20px;
    border-radius:50%;

   -webkit-animation: myOrbit 4s linear infinite; /* Chrome, Safari 5 */ 
   animation: myOrbit 4s linear infinite; /* Chrome, Firefox 16+,IE 10+, safari 5 */
}

@keyframes path {
    0% { transform: translateX(10px)  }
    10%   { transform:  translateX(0px)   translateY(20px)}
     20%   { transform:  translateX(20px)   translateY(40px)}
      30%   { transform:  translateX(50px)   translateY(52px)}
     40%   { transform:  translateX(150px)   translateY(50px)}
}

If you see in the code, you actually define the path for moving the ball as X, Y

+2
source

All Articles