Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why won't my Raphael JS animation loop?

Hi there I've made this animation using the Raphael framework. I want the star (logoStar) to spin indefinitely but it only runs once. Can anyone help? Thanks

window.onload = function () {
buildLogo();
}

var buildLogo = function () {
    var logo = Raphael("title",800,236);

    var logoStar = logo.path("M12.245 131.057L16.039 138.743L24.521 139.974L18.383 145.958L19.832 154.406L12.245 150.418L4.658 154.406L6.108 145.958L-0.03 139.974L8.452 138.743").attr({fill:"#fff",stroke:"none"});

    var starSpin = function () {
        logoStar.animate({rotation: "360"}, 5000, starSpin);
    }
    starSpin();
}
like image 416
KemanoThief Avatar asked Nov 09 '10 21:11

KemanoThief


2 Answers

var starSpin = function () {
    logoStar.attr({rotation: 0}).animate({rotation: 360}, 5000, starSpin);
}

Animation from 360° to 360° looks like there no animation, so you need to reset rotation to zero before.

like image 135
Dmitry Baranovskiy Avatar answered Nov 15 '22 19:11

Dmitry Baranovskiy


Since version 2 came out, the real way to have an infinitely looping animation is this:

var spin = Raphael.animation({transform: "r360"}, 2500).repeat(Infinity);
myElement.animate(spin);

Infinity is a property in Javascript, so don't enter it as a string.

Here's a working fiddle.

like image 26
Jason Avatar answered Nov 15 '22 20:11

Jason