首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >snapsvg .drag()属性定义

snapsvg .drag()属性定义
EN

Stack Overflow用户
提问于 2013-11-16 00:58:01
回答 2查看 1.3K关注 0票数 0

我只是从snap.svg开始。如果没有传递参数,element.drag()函数将提供一组默认值,否则您必须定义自己的onmoveonstartonend函数。

可以在您的onmove实现中使用onmove(dx,dx,x,y,event)的参数来移动元素。

如果我创建了一组元素,默认的g.drag()允许该组移动,但我不知道在我自己的onmove中放入什么才能使该组移动。

this.attr({cx: posx , cy: posy});.circle上工作。.group对应的xy是什么?

EN

回答 2

Stack Overflow用户

发布于 2013-11-17 06:16:52

下面是我刚刚测试的一个例子:

代码语言:javascript
复制
var s = Snap("#svg");

Snap.load("draw.svg", function(f) {
g = f.select("g");
s.append(g);

g.cx = 40;
g.cy = 140;
g.ox = 0;
g.oy = 0;

g.drag(dragging, startDrag, function(evt) {
            console.log("dropped at: "+ evt.x + ", " + evt.y);
        });


});

startDrag = function(posx, posy) {
  this.ox = posx - this.cx;
  this.oy = posy - this.cy;
}

dragging = function(dx, dy, posx, posy) {
  this.cx = posx - this.ox;
  this.cy = posy - this.oy;
  t = 't' + this.cx + ',' + this.cy;
  this.transform(t);
}

希望这能有所帮助。

票数 0
EN

Stack Overflow用户

发布于 2013-12-11 18:12:44

代码语言:javascript
复制
dragging = function(dx, dy, posX, poxY, event){
    this.transform("translate("+posX+","+posY+")");
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20006469

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档