Created
October 2, 2013 11:22
-
-
Save jorisroovers/6792268 to your computer and use it in GitHub Desktop.
Relies on pathAnimator.js and d3.js
This file contains 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
// requires snap-svg.js | |
function animateOverPath(el, path, duration, callback) { | |
len = path.getTotalLength(); | |
Snap.animate(0, len, function (l) { | |
var dot = path.getPointAtLength(l); | |
x = dot.x - el.getBBox().width/2; | |
y = dot.y - el.getBBox().height/2; | |
el.attr({ | |
transform: "t" + [x,y] + "r" + (dot.alpha - 180) | |
}); | |
}, duration, callback); | |
} |
This file contains 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
// requires d3.js and pathAnimator.js | |
function animatePacket (path, packet, speedz, finishCallback){ | |
var pathAnimator = new PathAnimator(path); | |
pathAnimator.start( speedz, step, false, 0 /* startoffset */, finish); | |
function step(point, angle) { // do something every "frame" with: point.x, point.y & angle | |
packet.attr("x", point.x - packet.attr("width")/2).attr("y", point.y - packet.attr("height")/2); | |
} | |
function finish() { | |
finishCallback(packet); | |
} | |
} | |
// usage | |
var originalPacket = self.networkDiagram.select("#packetSelector").node(); | |
var packet = self.networkDiagram.select("#layer2").select(function() { return this.appendChild(originalPacket.cloneNode(true)); }) | |
var srcPath = self.networkDiagram.select("#path-selector").attr("d"); | |
animatePacket(srcPath, packet, 1, function(pckt){ | |
console.log("done"); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment