-1

I have found a JSFiddle that has some great code to animate a ball - it rotates it through 360 deg. What I would like to do is have the ball constantly rotate through 360 deg - it needs to turn continuously. I have tried to achieve this but have had no success. I would be grateful for any help in adjusting this javascript.

$(document).ready(function(){
    var s=$('.ball').position();
    var g=s.left;
    var r=$('.ball').css('margin-left');
    $('.ball').css({'margin-left':'0px'});
    $('.ball').css({'margin-left':''+r+''});
    if(r=="0px")
    {
    $('.ball').css({'position':'absolute'});
    $('.ball').animate({'left':''+g+'px'});
    }
    $('.ball').css({'transform': 'rotate(360deg)','-webkit-transform': 'rotate(360deg)','-moz-transform': 'rotate(360deg)'});
});

This is the JSFiddle I found http://jsfiddle.net/996PJ/5/

gillers322
  • 249
  • 4
  • 17

1 Answers1

1

CSS animation can do that. Updated fiddle.

#box {
  width: 900px;
  height: 150px;
  position: relative;
  background: red;
  overflow: hidden;
}
.ball {
  width: 150px;
  height: 150px;
  animation: rotate 3s ease-in-out infinite;
  margin: 0px auto;
}
.ball img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
}
@keyframes rotate {
  0% {
    transform: rotate(0deg);
    -webkit-transform: rotate(0deg);
    -moz-transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
    -webkit-transform: rotate(360deg);
    -moz-transform: rotate(360deg);
  }
}
<br/>
<br/>
<div id="box">
  <div class="ball">
    <img src="http://blog.wiziq.com/wp-content/uploads/2013/11/5-150x150.png" />
  </div>
</div>
Pugazh
  • 9,453
  • 5
  • 33
  • 54