试图拖动组。为什么 origin 在这里不起作用?注意到当你第一次点击它时它是如何跳跃的吗?JSFIDDLE http://jsfiddle.net/airwwwave/pob7xhuo/基于此:http://bl.ocks.org/mbostock/1557377 http://bl.ocks.org/mbostock/1557377
var drag = d3.behavior.drag() // construct drag behavior
.origin(function() {
var t = d3.select(this);
return {x: t.attr("x"), y: t.attr("y")};
})
.on("drag", function(d,i) {
d.x += d3.event.dx
d.y += d3.event.dy
d3.select(this).attr("transform", function(d,i){
return "translate(" + [ d.x,d.y ] + ")"
})
});
你正在混合不同的设置位置的方式——你正在设置transform
and cx
and cyon the circles, but not on the
gelements that you want to drag. While it can be made to work by computing the various offsets, it's much easier if you set the position for the things you're interested in (i.e. the
g` 元素)并调用拖动行为。
var svgG = svg.append("g")
.attr("transform", function(d) { return "translate(" + [ d.x,d.y ] + ")"; })
.call(drag);
完整示例here https://jsfiddle.net/pob7xhuo/3/.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)