admin管理员组

文章数量:1357724

I am using D3.js to drag SVG elements, using concept of D3.js drag. drag is working fine but I want to call a function on dragend. How to do that?

Here is jsFiddle Link. I simply want to call a function on dragend.

Should I try

var drop = d3.behavior.drag()
  .on("dragend", function () { alert(); });

I am using D3.js to drag SVG elements, using concept of D3.js drag. drag is working fine but I want to call a function on dragend. How to do that?

Here is jsFiddle Link. I simply want to call a function on dragend.

Should I try

var drop = d3.behavior.drag()
  .on("dragend", function () { alert(); });
Share Improve this question edited Apr 10, 2013 at 12:36 Felix Kling 817k181 gold badges1.1k silver badges1.2k bronze badges asked Apr 10, 2013 at 11:20 Sudarshan TanwarSudarshan Tanwar 3,6073 gold badges27 silver badges39 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

You seemed to be trying to do some kind of nested dragging or something, the following should work:

 var drag1 = d3.behavior.drag()
    .on("drag", dragmove)
    .on("dragend", function () { alert("drag ended"); });

Full example: http://jsfiddle/xnjGD/

Quick mention if anyone still needs something like this, d3.behaviour was deprecated as well as dragend. If you still need the functionality it should look something like this:

d3.drag().on("end", (_event, dimension) => {
    console.log("alert ended for : " dimension)
  })

(for more informations: https://github./d3/d3/blob/master/CHANGES.md#dragging-d3-drag)

本文标签: javascripthow to add dragend event on svg elementStack Overflow