如何使用snap svg拖动元素集?
var s = Snap("#svgmain");
var onloadmap = Snap.load("SVGFILES/3k1e-test.svg",function(lf)
{
s.append(lf);
var all_rect = s.selectAll('rect');
var all_path = s.selectAll('path');
group_of_rects_and_paths.push(all_path,all_rect);
var dragger = function() {
this.ox = this.type == "rect" ? this.attr("x") : this.attr("cx");
this.oy = this.type == "rect" ? this.attr("y") : this.attr("cy");
},
move = function(dx, dy) {
var mx = Number(this.ox) + dx;
var my = Number(this.oy) + dy;
var att = this.type == "rect" ? {
x: mx,
y: my
} : {
cx: mx,
cy: my
};
this.attr(att);
},
up = function() {
};
group_of_rects_and_paths.drag(move,dragger,up);
})
但是没有任何东西与元素集合,只有错误:
Uncaught TypeError: undefined is not a function
有什么问题? 请帮忙。
问题解决了:
var g = s.group();
var onloadmap = Snap.load("SVGFILES/3k1e-test.svg",function(lf)
{
g.append(lf);
......
g.drag();
但这是一个新问题。 如何在边框中拖动此组?