目前,我正在尝试实现拖放功能。

我有这个。

var drag = d3.behavior.drag();
  drag.on('drag', function () {
    console.log("drag start");
  })
  drag.on('dragend', function () {
    console.log("drag stop");
  })

  selection = d3.select('.right.menu');
  selection.call(drag);


Wich Works,但现在我想看到div在屏幕上移动,现在我只获得控制台,如何完成此操作,甚至更好地指导有关如何命名此方法/事件以进行一些研究的指南。

更新资料

当前解决方案。

var drag = d3.behavior.drag();
  drag.on('drag', function () {
console.log(selection);
    selection.style("left", d3.event.x+"px").style("top", d3.event.y+"px").style("position", "inherit");
  })
  drag.on('dragend', function () {
    console.log("drag stop");
  })

  selection = d3.select('.right.menu')
  selection.call(drag);

最佳答案

这是一个简单的示例,该示例使用css position:absolute移动div并根据拖动来修改顶部和左侧偏移。

appdiv.style("left", d3.event.x+"px").style("top", d3.event.y+"px");


Fiddle

10-08 04:59