score:1

Accepted answer

Your code is disassociating the mouse from the circle. It's working against the "difference" is position instead of the absolute position.

Try:

function dragmove(d) {
    d.x += d3.event.dx;
    d.y += d3.event.dy;
    movex = Math.round(d.x / 50) * 50;
    movey = Math.round(d.y / 50) * 50;
    d3.select(this).attr("transform", "translate(" + movex + "," + movey + ")");
}

Updated fiddle.


Related Query

More Query from same tag