Last active
December 17, 2015 09:28
-
-
Save JohnDelacour/5587174 to your computer and use it in GitHub Desktop.
Translate and Rotate 1
This file contains hidden or 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> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>Translate and Rotate</title> | |
| <script src="http://d3js.org/d3.v3.min.js"></script> | |
| <link rel="stylesheet" type="text/css" href="translate_and_rotate.css"> | |
| </head> | |
| <body> | |
| <div id="legend"> | |
| <p> | |
| Click on the background to activate | |
| </p> | |
| <p> | |
| Duration: <input class="box" type="text" | |
| id="ms" value="3.0" /> seconds. | |
| </p> | |
| </div> | |
| <svg width="960" height="500"> | |
| <defs> | |
| <g id="shape" transform="rotate(0)"> | |
| <rect x="-50" y="-50" width="100" height="100" /> | |
| <circle r="4" fill="none" /> | |
| </g> | |
| </defs> | |
| <rect id="background" width="960" height="500" /> | |
| <path id="track" d="M 50 200 h 850" /> | |
| <g id="g0"> | |
| <g id="g1"> | |
| <use xlink:href="#shape" /> | |
| </g> | |
| </g> | |
| </svg> | |
| <script type="text/javascript"> | |
| var roll = function() { | |
| var text_entered = document.getElementById('ms').value * 1000; | |
| text_entered ? t = text_entered : t = 3.0; | |
| var 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(180)"); | |
| return; | |
| } | |
| d3.select("#background") | |
| .on("click", function() { return roll(); } ); | |
| roll(); | |
| </script> | |
| </body> | |
| </html> |
This file contains hidden or 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
| .box { | |
| width:2.5em; | |
| height:1em; | |
| border:solid #eee 1px; | |
| padding-left:0.5em; | |
| border-radius: 1px; | |
| box-shadow: 0px 0px 0px 3px rgba(205,0,205,0.2); | |
| } | |
| #background { | |
| fill:#dde; | |
| } | |
| #legend { | |
| position:absolute; | |
| left:50px; | |
| top:10px; | |
| font:12pt sans-serif; | |
| color:navy; | |
| } | |
| #shape { | |
| fill: #bbe; | |
| opacity: 0.8; | |
| stroke: magenta; | |
| } | |
| #track { | |
| stroke:magenta; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment