Javascript 拉斐尔拖拉整套
我在fiddle中使用了drag函数,但我想同时移动rect和text,因为我将drag应用于集合,而不仅仅是rect。如何更改拖动功能以移动整个集合Javascript 拉斐尔拖拉整套,javascript,drag-and-drop,raphael,Javascript,Drag And Drop,Raphael,我在fiddle中使用了drag函数,但我想同时移动rect和text,因为我将drag应用于集合,而不仅仅是rect。如何更改拖动功能以移动整个集合 start = function() { this.ox = this.type == "rect" ? this.attr("x") : this.attr("cx"); this.oy = this.type == "rect" ? this.attr("y") : this.attr("cy");
start = function() {
this.ox = this.type == "rect" ? this.attr("x") : this.attr("cx");
this.oy = this.type == "rect" ? this.attr("y") : this.attr("cy");
this.attr({
opacity: 1
});
// Save the dragged object in global namespace.
window.someVar = this;
},
move = function(dx, dy) {
var att = this.type == "rect" ? {
x: this.ox + dx,
y: this.oy + dy
} : {
cx: this.ox + dx,
cy: this.oy + dy
};
this.attr(att);
},
up = function() {
this.attr({
opacity: .5
});
delete window.someVar;
};
更改设置参考的属性。如果您有多个集合,您需要检查this.id是否为,并使用该集合
paper = Raphael(0, 0, 500, 500);
var ox = 0;
var oy = 0;
var screenSet = paper.set();
screenSet.push(paper.rect(0, 0, 100, 75, 0).attr({
fill: 'red', stroke: 'none'
}));
screenSet.push(paper.text(0 , 0 ,"Text").attr({ "text-anchor": "start" }));
start = function() {
ox = this.attr("x");
oy = this.attr("y");
screenSet.attr({
opacity: 1
});
},
move = function(dx, dy) {
var att ={
x: ox + dx,
y:oy + dy
};
screenSet.attr(att);
},
up = function() {
this.attr({
opacity: .5
});
ox = 0, oy = 0;
};
screenSet.drag(move, start, up);