0

I have the following function that I want to continously animate an image as fallback for CSS animation for IE9.

Problem is it rotates once then on recursion now always equals to 360. It never starts at 0 again.

Thanks :)

var App = {


    init: function() {
       console.log(Modernizr.cssanimations);
       this.rotateSpinners();
    },

    rotateSpinners: function() {
        $('.speed2').each(function() {
            App.rotate($(this));
        });
    },

   rotate: function(element) {

       //console.log('---');
       //console.log(element);

       $(element).stop(true, true).animate(
           {
               rotation: 360
           },
           {
               duration: 3600,
               step: function(now) {
                   $(this).css({"transform": "rotate("+now+"deg)"});
                   //counts up to 360, second run always returns 360 without counting
                   console.log(now); 
               },
               done: function() {
                   // tried to reset here
                   //$(this).css({"transform": "rotate(0deg)"}); 
                   App.rotate($(this));
               }
           }
       );

   }

};

App.init();
Markus
  • 2,214
  • 3
  • 19
  • 32

1 Answers1

0

Try

var App = {

    init: function() {
       // console.log(Modernizr.cssanimations);
       this.rotateSpinners();
    },

    rotateSpinners: function() {
        $(".speed2").each(function() {
            App.rotate(this);
        });
    },

    rotate: function(element) {
       // set, reset `element.style.rotation` at `0`
       element.style.rotation = 0;
       $(element).stop(true, true).animate(
           {
               rotation: 360
           },
           {
               // set `easing` at `linear`
               easing:"linear",
               duration: 3600,
               step: function(now) {
                   $(this).css("transform", "rotate(" + now + "deg)");               
                   console.log(now); 
               },
               done: function() {                     
                 App.rotate(this);
               }
           }
       );

   }

};

App.init();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="speed2">abc</div>
guest271314
  • 1
  • 15
  • 104
  • 177
  • @Markus `rotation` set, reset to `0` at `element.style.rotation = 0;` before `.animatie()` called within `.rotate()` :) – guest271314 Mar 31 '15 at 15:03