-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathanimate-object-path.js
41 lines (33 loc) · 1.29 KB
/
animate-object-path.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
(function() {
Snap.plugin( function( Snap, Element, Paper, global ) {
Element.prototype.drawAtPath = function( path, timer, options) {
var myObject = this, bbox = this.getBBox(1);
var point, movePoint = {}, len = path.getTotalLength(), from = 0, to = len, drawpath = 0, easing = mina.linear, callback;
var startingTransform = '';
if( options ) {
easing = options.easing || easing;
if( options.reverse ) { from = len; to = 0; };
if( options.drawpath ) {
drawpath = 1;
path.attr({
fill: "none",
strokeDasharray: len + " " + len,
strokeDashoffset: this.len
});
};
if( options.startingTransform ) {
startingTransform = options.startingTransform;
};
callback = options.callback || function() {};
};
Snap.animate(from, to , function( val ) {
point = path.getPointAtLength( val );
movePoint.x = point.x - bbox.cx; movePoint.y = point.y - bbox.cy;
myObject.transform( startingTransform + 't' + movePoint.x + ',' + movePoint.y + 'r' + point.alpha);
if( drawpath ) {
path.attr({ "stroke-dashoffset": len - val });
};
}, timer, easing, callback );
};
});
})();