我已經使用了這個簡單的虛擬文件來做一些測試。預期的結果是沿路徑拖動紅色圓圈。問題是,我無法弄清楚如何關聯這兩種形狀。如何沿給定路徑拖動形狀
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<script src="raphael-min.js"></script>
</head>
<body>
<script type="text/javascript">
// Creates canvas 320 × 200 at 10, 50
var r = Raphael(10, 50, 320, 200);
var p = r.path("M100,100c0,50 100-50 100,0c0,50 -100-50 -100,0z").attr({stroke: "#ddd"}),
e = r.ellipse(104, 100, 4, 4).attr({stroke: "none", fill: "#f00"}),
/*var c = r.circle(100, 100, 50).attr({
fill: "hsb(.8, 1, 1)",
stroke: "none",
opacity: .5
});*/
var start = function() {
// storing original coordinates
this.ox = this.attr("cx");
this.oy = this.attr("cy");
this.attr({opacity: 1});
},
move = function (dx, dy) {
// move will be called with dx and dy
this.attr({cx: this.ox + dx, cy: this.oy + dy});
},
up = function() {
// restoring state
this.attr({opacity: 1});
};
e.drag(move, start, up);
</script>
</body>
</html>
的主要想法是讓類似animateAlong但拖,而不是動畫的東西。 – Guillermo
這是一個jsFiddle供人們使用:http://jsfiddle.net/8T9NQ/ – Joe
一般來說,您需要將光標位置投影到路徑上,找到路徑上最近的點。很有可能在最靠近光標的路徑上可能有兩個(或更多或無限)點,因此您需要消除歧義以選擇最佳點。 – Phrogz