admin管理员组文章数量:1405118
I am using Rahael.js library.
If I have a path:
var mypath = paper.path("M10 10L90 90");
I would like to implement the feature that when mouse drag one side of the path line, the other side of the path line keep in the original position while the dragged side will move with mouse. That's like a drag and pin feature. How to implement it?
I am not sure how to update a path attribute by using raphael drag() function.
var start = function () {
},
move = function (dx, dy) {
//How to update the attribute of one side of the path here
},
up = function () {
};
mypath.drag(move, start, up);
I am using Rahael.js library.
If I have a path:
var mypath = paper.path("M10 10L90 90");
I would like to implement the feature that when mouse drag one side of the path line, the other side of the path line keep in the original position while the dragged side will move with mouse. That's like a drag and pin feature. How to implement it?
I am not sure how to update a path attribute by using raphael drag() function.
var start = function () {
},
move = function (dx, dy) {
//How to update the attribute of one side of the path here
},
up = function () {
};
mypath.drag(move, start, up);
Share
asked Aug 2, 2011 at 7:40
MellonMellon
39k79 gold badges193 silver badges265 bronze badges
2 Answers
Reset to default 7 +50You need a second element that acts like a "handle", make that element draggable and then update your line path:
var paper = Raphael('canvas', 300, 300);
var path = paper.path("M10 10L90 90");
var pathArray = path.attr("path");
handle = paper.circle(90,90,5).attr({
fill: "black",
cursor: "pointer",
"stroke-width": 10,
stroke: "transparent"
});
var start = function () {
this.cx = this.attr("cx"),
this.cy = this.attr("cy");
},
move = function (dx, dy) {
var X = this.cx + dx,
Y = this.cy + dy;
this.attr({cx: X, cy: Y});
pathArray[1][1] = X;
pathArray[1][2] = Y;
path.attr({path: pathArray});
},
up = function () {
this.dx = this.dy = 0;
};
handle.drag(move, start, up);
http://jsfiddle/TfE2X/
Mask the end of the path with a transparent rect element and animate the coordinates from the current x,y to the translated x,y position of the rect element and keep updating the path simultaneously on mousemove.
本文标签: javascriptRaphaeljsHow to drag one side of the path in my caseStack Overflow
版权声明:本文标题:javascript - Raphael.js : How to drag one side of the path in my case? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744883859a2630367.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论