Skip to content

Instantly share code, notes, and snippets.

@majomo
Last active May 2, 2016 02:08
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 majomo/521b0d2e931b19b2b57fb6d92d4c0e15 to your computer and use it in GitHub Desktop.
Save majomo/521b0d2e931b19b2b57fb6d92d4c0e15 to your computer and use it in GitHub Desktop.
Translate and Rotate 2
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://d3js.org/d3.v3.min.js"></script >
</head>
<body>
<h4 style="position:absolute; left:50px; top:10px; font:12pt sans-serif; color:navy;">
Click the background to reanimate
</h4>
<h4 style="position:absolute; left:50px; top:10px; font:12pt sans-serif; color:navy;">
Click the background to reanimate
</h4>
<svg width="960" height="500">
<defs>
<g id="shape" transform="rotate(0)">
<path d=
"M -40 -90
c -20 33 20 66 0 100
a 60 60 0 0 0 100 0
q 30 -30 0 -100 z"
fill="#bce" opacity="0.8" stroke="magenta" />
<circle r="2" fill="none" stroke="magenta" />
</g>
</defs>
<rect id="background" width="960" height="500" fill="aliceblue" />
<path d="M 50 200 h 850" stroke="magenta" />
<g id="g0">
<g id="g1">
<use xlink:href="#shape" />
</g>
</g>
</svg>
<script type="text/javascript">
var roll = function() {
var t = 4000, d = 500, e = "linear"
d3.select("#g1")
.attr("transform", "translate(100 200)")
.transition()
.delay(d)
.duration(t)
.ease(e)
//.attr("transform", "translate(850 200)");
d3.select("#shape")
.attr("transform", "rotate(0)")
.transition()
.delay(d)
.duration(t)
.ease(e)
.attr("transform", "rotate(90)");
return;
}
d3.select("#background")
.on("click", function() { return roll(); } );
roll();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment