I've got a problem with what looks to me like perfectly fine simple Raphael.js code to animate a path moving from one location to another by using the .animate()
method on the path:
attribute, passing the path in its new location.
But, instead of smoothly transition from the old path to the new, it pauses for an amount of time equal to the transition time, then jumps straight to the end of the animation.
Everything in the code that I can see seems to follow the documentation and standard patterns, and since it's not crashing but giving unexpected behaviour, I've got no messages or direct feedback to work with.
The animation works, but skips the intermediate transition steps. How, why?
Here's a JSBIN live demo of the code...
...and here's the example code.
var paper = Raphael("huh", '100%', '100%');
paper.customAttributes.pathX = function( x ) {
var path = this.attr('path');
var origin = getPathOrigin(path);
return { path: Raphael.transformPath(path, ['T', x - origin.x, 0 ]) };
};
paper.customAttributes.pathY = function( y ) {
var path = this.attr('path');
var origin = getPathOrigin(path);
return { path: Raphael.transformPath(path, ['T', 0, y - origin.y]) };
};
paper.customAttributes.pathXY = function( x,y ) {
var path = this.attr('path');
var origin = getPathOrigin(path);
return { path: Raphael.transformPath(path, ['T', x - origin.x, y - origin.y ]) };
};
function getPathOrigin(path) {
return {x: path[0][1], y: path[0][2]};
}
var path = paper.path('M 100 100 L 105 105 L 95 105 L 95 95 L 105 95 L 100 100');
var origin = getPathOrigin(path);
path.attr({pathX: origin.x, pathY: origin.y, pathXY: [origin.x, origin.y]});
path.animate({pathX: 200},1000, 'linear', function(){
path.animate({pathY: 200},1000, 'elastic', function(){
path.animate({pathXY: [50,50]}, 1000, 'bounce');
});
});
path.animate({pathX: 200},1000, 'linear');