Created
January 22, 2016 08:59
-
-
Save fbukevin/5e44206e82b18d747c9e to your computer and use it in GitHub Desktop.
Snap.svg plug - Animate along path
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
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