【发布时间】:2015-09-15 02:15:33
【问题描述】:
使用 rapheal 很简单,我成功地沿路径制作动画,但我无法反转动画方向,,,只是如何在单击同一路径时使其动画到另一个方向。
var paper = Raphael(0,0,1024,768);
var pathOne = paper.path(['M', 15,15 , 100,75]).attr({'stroke-width':18}).data("id",1);
//and this is just the circle
var circle = paper.circle(0, 0, 13).attr({
fill: '#09c', cursor: 'pointer'
});
//make the path as custom attribute so it can ba accessed
function pathPicker(thatPath){
paper.customAttributes.pathFactor = function(distance) {
var point = thatPath.getPointAtLength(distance * thatPath.getTotalLength());
var dx = point.x,
dy = point.y;
return {
transform: ['t', dx, dy]
};
}
}
//initialize for first move
pathPicker(pathOne);
circle.attr({pathFactor: 0}); // Reset
//Asign first path and first move
function firstMove(){
circle.animate({pathFactor: 1}, 1000});
}
pathOne.click(function(){
firstMove();
});
【问题讨论】:
-
你能不能让它在 jsfiddle 上运行,因为它不能运行。
-
我更新了它现在应该可以工作的代码。谢谢