基本上我想沿着路徑滾動一個對象。我見過幾個線程尋找類似的解決方案,不使用paper.js,但我想知道是否可以使用paper.js。或者有人可以給我一個工作的對象跟蹤svg曲線,因爲我無法得到任何工作。我最終希望有一個div鏈。沿着路徑滾動Paper.js
// vars
var point1 = [0, 100];
var point2 = [120, 100];
var point3 = [120, 150];
// draw the line
var path = new Path();
path.add(new Point(point1), new Point(point2), new Point(point3));
path.strokeColor = "#FFF";
path.closed = true;
// draw the circle
var circle = new Path.Circle(0,100,4);
circle.strokeColor = "#FFF";
// target to move to
var target = point2;
// how many frame does it take to reach a target
var steps = 200;
// defined vars for onFrame
var dX = 0;
var dY = 0;
// position circle on path
circle.position.x = target[0];
circle.position.y = target[1];
function onFrame(event) {
//check if cricle reached its target
if (Math.round(circle.position.x) == target[0] && Math.round(circle.position.y) == target[1]) {
switch(target) {
case point1:
target = point2;
break;
case point2:
target = point3;
break;
case point3:
target = point1;
break;
}
// calculate the dX and dY
dX = (target[0] - circle.position.x)/steps;
dY = (target[1] - circle.position.y)/steps;
}
// do the movement
//circle.position.x += dX;
//circle.position.y += dY;
}
這裏是的jsfiddle: http://jsfiddle.net/J9xgY/12/
謝謝!
你的問題還不清楚 - 你能解釋一下你的意思嗎?「用滾動條跟蹤路徑比例?」另外,請記住,paper.js不是移動外部'div's的最佳工具,而是在'canvas'元素中顯示圖形。 –
基本上我想沿路徑滾動一個對象。 – user2517605
你想沿三角形路徑移動圓圈嗎? –