您需要分割路徑以調整三角形的位置。我是能夠用眼睛靠撿出來要做到這一點,其中第二個「M」是路徑:
var playB = Raphael('playB', 200, 200);
var circle = playB.path("M64,5.864C31.892,5.864,5.864,31.892,5.864,64c0,32.108,26.028,58.136,58.136,58.136c32.108,0,58.136-26.028,58.136-58.136C122.136,31.892,96.108,5.864,64,5.864z");
var triangle = playB.path("M26.736,102.728L97.264,62L26.736,21.272V102.728z");
然後你可以移動的三角過來:
triangle.attr("transform", "T15,0");
要保持性能和動畫完好,都添加到拉斐爾組:
var playBP = playB.set();
playBP.push(circle, triangle);
playBP.attr({
'stroke-width': 5,
'stroke': "#000",
'fill': "#fff",
'opacity': 1
});
然後你只需要一個小的變化:改變「這個」,在鼠標懸停命令「playBP」。這看起來可能是多餘的,但「this」指的是被蒙上陰影的單個元素,而不是集合。
var speed = 5;
playBP.mouseover(function(){
playBP.animate({
'stroke-width': 10,
'stroke': "#fff",
'fill': "#000",
'opacity': .9
}, 1000, 'elastic');
});
playBP.mouseout(function(){
playBP.stop().animate({
'stroke-width': 5,
'stroke': "#000",
'fill': "#fff",
'opacity': 1
}, speed*4, 'elastic');
});
jsFiddle updated
如果您只想修復路徑,你可以使用Raphael.mapPath()函數來得到調整X/Y爲三角形,像這樣:
console.log(Raphael.mapPath(triangle.attr("path"), triangle.matrix));
請問triangle.matrix是什麼?一個例子? –