Skip to content

Instantly share code, notes, and snippets.

@fbukevin
Created January 22, 2016 08:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fbukevin/5e44206e82b18d747c9e to your computer and use it in GitHub Desktop.
Save fbukevin/5e44206e82b18d747c9e to your computer and use it in GitHub Desktop.
Snap.svg plug - Animate along path
Snap.plugin(function (Snap, Element, Paper, glob, Fragment) {
var elproto = Element.prototype;
elproto.animateAlongPath = function (path, el, start, duration, easing) {
var callback = this;
el.transform('t0,0');
var len = Snap.path.getTotalLength(path),
elBB = el.getBBox(),
elCenter = {
x: elBB.x + (elBB.width / 2),
y: elBB.y + (elBB.height / 2),
};
Snap
.animate(start, len, function (value) {
var movePoint = Snap.path.getPointAtLength(path, value);
el.transform('t'+ (movePoint.x - elCenter.x) + ',' + (movePoint.y - elCenter.y));
}, duration, easing, function(){
callback.animateAlongPath(path, el, start, duration, easing);
});
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment