Skip to content

Instantly share code, notes, and snippets.

@mrtriangle
Last active June 7, 2016 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrtriangle/11222485 to your computer and use it in GitHub Desktop.
Save mrtriangle/11222485 to your computer and use it in GitHub Desktop.
Ripples
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Clicks</title>
<style>
body {
font-family: "helvetica";
height: 100%;
}
svg {
cursor: pointer;
width: 400px;
height: 400px;
}
circle {
fill: none;
stroke: #cc0000;
}
</style>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
</head>
<body>
<h1>Click Around, Have Some Fun.</h1>
<script type="text/javascript">
var r = 400;
var svg = d3.select("body")
.append("svg");
var positionLabel = svg.append("text")
.attr("x", 10)
.attr("y", 30);
svg.on("click", function () { //<-D
for (var i = 1; i < 5; ++i) {
var position = d3.mouse(svg.node());
var circle = svg.append("circle")
.attr("cx", position[0])
.attr("cy", position[1])
.attr("r", 0)
.style("stroke-width", 5 / (i))
.transition()
.delay(Math.pow(i, 2.5) * 50)
.duration(2000)
.ease('quad-in')
.attr("r", r)
.style("stroke-opacity", 0)
.each("end", function () {
d3.select(this).remove();
});
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment