2014-05-09 63 views
0

我正在使用拖動功能,因爲我在小提琴中使用拖曳功能,但我想移動rect和文本togehter,因爲我不僅將拖拽應用到了該矩形。我怎樣才能改變我的拖動功能來移動整個集合?拉斐爾拖整個集

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; 
    }; 
上一套refrance

http://jsfiddle.net/Margo/Q3EBw/3/

回答

0

變化ATTR。如果你有很多套,你需要檢查這個.id,並使用該套。

http://jsfiddle.net/Margo/Q3EBw/5/

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);