D3.JS实例,旋转的色彩方块

Talk is cheap,show me the code.

http://www.w3school.com.cn/tiy/t.asp?f=html_basic,把下面代码复制到这个网站上观看。

做出这个的步骤,

1.先加入svg

2.选中所有矩形,添加矩形。

3.调整矩形的颜色,动作等。


<!DOCTYPE html>
<meta charset="utf-8">
<title>Transform Transitions</title>
<style>

body {
  margin: 0;
}

rect {
  stroke: #fff;
  stroke-width: .1px;
}

</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>

var w = 960,
    h = 500,
    z = 20,
    x = w / z,
    y = h / z;
var svg=d3.select("body").append("svg");
svg.attr("width",w)
   .attr("height",h);
svg.selectAll("rect")
   .data(d3.range(x*y))
   .enter()
   .append("rect")
   .attr("width",z)
   .attr("height",z)
   .attr("transform",trans)
   .attr("fill",beautiful)
   .on("mouseover",mouseover);
function beautiful(d){
    return d3.hsl(Math.floor(360*(d/x)/y),1,0.5);
}
function trans(d){
     return "translate("+(d%x)*z+","+Math.floor(d/x)*z+")";
}
function mouseover(d) {
  this.parentNode.appendChild(this);

  d3.select(this)
      .style("pointer-events", "none")
    .transition()
      .duration(750)
      .attr("transform", "translate(480,480)scale(23)rotate(180)")
    .transition()
      .delay(1500)
      .attr("transform", "translate(0,0)scale(100)")
      .style("fill-opacity", 0)
      .remove();
}

</script>


你可能感兴趣的:(svg,实例,d3.js,信息可视化)