2017-11-10 115 views
1

我有一個路徑,使形狀和能夠旋轉,但我無法弄清楚如何我可以得到形狀/路徑向下移動屏幕。我看過其他解決方案,但我似乎無法讓他們工作。謝謝。JavaScript拉斐爾動畫路徑

leftRec = paper.path("M400 50 L380 70 420 90 380 110 420 130 400 150 350 150 350 50z"); 
leftRec.attr("fill","#f00"); 
leftRec.animate({transform:"r-70,400,150"}, 2000, "ease-in"); 

leftRec.animate({cy: 600, cx: 200}, 2000); 
+0

所以,你會想要形狀旋轉,向下移動屏幕或向下移動就足夠了? –

回答

0

同時進行旋轉和平移,可使用animate方法

var leftRec = paper.path("M400 50 L380 70 420 90 380 110 420 130 400 150 350 150 350 50Z"); 
leftRec.attr("fill","#f00"); 
leftRec.animate({transform: "T0,500R-90"}, 1000, "ease-in"); 

爲了第一,然後翻譯進行旋轉,利用該回調在animate方法

var leftRec = paper.path("M400 50 L380 70 420 90 380 110 420 130 400 150 350 150 350 50Z"); 
leftRec.attr("fill","#f00"); 
leftRec.animate({transform:"r-90,400,150"}, 1000, "ease-in", function() { 
    this.animate({ 
     path: Raphael.transformPath('M400 50 L380 70 420 90 380 110 420 130 400 150 350 150 350 50Z', 'T-500,0') 
    }, 1000); 

    // The below approach could have worked in theory but probably the coordinate system change might 
    // tamper with the subsequent transform. I am not so sure. 
    // this.animate({transform: "T0,500"}, 1000) 
}); 

在這兩種情況下,形狀垂直移動500px。

這可能不是最好的解決方案,如果有更好的方法來解決這個問題,請糾正/改進。

+0

謝謝,我發現最上面的代碼和預期完全一樣。 –