Built with blockbuilder.org
Last active
February 28, 2016 00:40
-
-
Save jfost00/3ed40f11a73b1b36f4ae to your computer and use it in GitHub Desktop.
drag and drop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment