我基于 这个 拖放示例工作:
我想拖一个组。我将两个矩形放在一个组中,现在想要拖放整个组,在我的代码中拖放适用于单个矩形但不适用于组。
这是我的代码:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"> </script>
<title>Drag And Drop</title>
</head>
<body>
<div id="viz"></div>
<script type="text/javascript">
var vizSVG = d3.select("#viz")
.append("svg")
.attr("width", 400)
.attr("height", 300);
var group =d3.select("svg")
.append("g")
.attr("id","group1")
.attr("x",50)
.attr("y", 140)
//.attr("fill", "yellow")
// .call(d3.behavior.drag().on("drag", move));
group.append("rect")
.attr("id", "bluerect")
.attr("x", 50)
.attr("y", 140)
.attr("width", 50)
.attr("height", 50)
.attr("stroke", "red")
.attr("fill", "blue")
.attr("opacity","0.5")
.call(d3.behavior.drag().on("drag", move));
group.append("rect")
.attr("id", "redrect")
.attr("x", 110)
.attr("y", 140)
.attr("width", 50)
.attr("height", 50)
.attr("stroke", "blue")
.attr("fill", "red")
.call(d3.behavior.drag().on("drag", move));
function …Run Code Online (Sandbox Code Playgroud)