D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
jfost00
Full window
Github gist
drag and drop
Built with
blockbuilder.org
<!DOCTYPE html> <head> <meta charset="utf-8"> <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script> <style> body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } svg { width:100%; height: 100% } </style> </head> <body> <script> var width = 600, height = 400, circle1; var drag = d3.behavior.drag() .on('dragstart', dragStart) .on('drag', dragElement) .on('dragend', dragEnd); d3.select("#circle1").call(drag); function dragStart(d, i){} function dragElement(d, i) { circle1.attr("cx", d3.event.sourceEvent.pageX) .attr("cy", d3.event.sourceEvent.pageY); } function dragEnd(d, i){} var svg = d3.select("body") .append("svg") .attr("width", width) .attr("height", height); circle1 = svg.append("circle") .attr("id", "circle1") .attr("cx", 50) .attr("cy", 50) .attr("r", 72) .attr("fill", "rgb(69,96,159)") .call(drag); </script> </body>
https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js