Create a gist now

Instantly share code, notes, and snippets.

@maelp /
Last active Aug 29, 2015

Fast prototyping tricks - Transition along invisible path
<!DOCTYPE html>
<meta charset="utf-8">
body {
width: 960px;
padding-top: 40px;
margin: auto;
position: relative;
svg {
width: 100%;
max-height: 400px;
<script src="" charset="utf-8"></script>
<script type='text/javascript'>
function animateGrowingCircle(fromRadius, toRadius) {
var animateFunction = function () {
.attr('r', fromRadius)
.attr('r', toRadius)
.attr('r', fromRadius)
.each('end', function () {;
return animateFunction;
function translateAlongPath(path, offset) {
var l = path.getTotalLength();
var tx = offset[0],
ty = offset[1];
return function() {
return function(t) {
var p = path.getPointAtLength(t * l);
.attr('cx', p.x + tx)
.attr('cy', p.y + ty);
function reload() {'svg').remove();
d3.xml('iPhone.svg', 'image/svg+xml', function (error, data) {'body').node().appendChild(data.documentElement);
var svg ='svg');
var mainScreen ='#MainScreen');
var animationElements ='#AnimationElements');'display', 'none');
var replayButton ='#ReplayButton')
.style('display', 'none')
.style('opacity', 0.0)
.style('cursor', 'pointer')
.on('click', reload);
var circle ='#Circle');
var offset = d3.transform(animationElements.attr('transform')).translate;
var motionPath ='#MotionPath');
.tween('translateAlongPath', translateAlongPath(motionPath.node(), offset))
.each('end', function () {
var circleAnimationMaxRadius ='#CircleAnimationMaxRadius');
var r = +circle.attr('r');
var r2 = +circleAnimationMaxRadius.attr('r');
.style('display', 'block')
.style('opacity', 1.0);
.each(animateGrowingCircle(r, r2));
window.addEventListener('load', function () {
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment