Monday, April 16, 2018

Rotate an image n number of times

Rotate an image n number of times



script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">

$(document).ready(function(){
 
    var elemn = $("a[title|='Refresh Access'] > img");
    AnimateRotate(360,"infinite",elemn);
   
    }); 
   
 function AnimateRotate(angle,repeat,elemn) {
    var duration= 1000;
    setTimeout(function() {
        if(repeat && repeat == "infinite") {
            AnimateRotate(angle,repeat,elemn);
        } else if ( repeat && repeat > 1) {
            AnimateRotate(angle, repeat-1,elemn);
        }
    },duration)   
    var $elem = elemn;
    $({deg: 0}).animate({deg: angle}, {
        duration: duration,
        step: function(now) {
            $elem.css({
                'transform': 'rotate('+ now +'deg)'
            });
        }
    });
}

No comments:

Post a Comment