Skip to content

armgit / anime

Public Imported from GitHub
0

JavaScript animation engine

Add pathDashoffset()

Julian Garnier9d539f1f7366
diff --git a/anime.js b/anime.js
index 004bc034..7e3589ab 100644
--- a/anime.js
+++ b/anime.js
@@ -399,6 +399,12 @@
return is.obj(val) && objectHas(val, 'totalLength');
}
+ function setDashoffset(el) {
+ const pathLength = el.getTotalLength();
+ el.setAttribute('stroke-dasharray', pathLength);
+ return pathLength;
+ }
+
function getPath(path, percent) {
const el = is.str(path) ? selectString(path)[0] : path;
const p = percent || 100;
@@ -783,6 +789,7 @@
anime.remove = removeTargets;
anime.getValue = getOriginalTargetValue;
anime.path = getPath;
+ anime.pathDashoffset = setDashoffset;
anime.bezier = bezier;
anime.easings = easings;
anime.timeline = timeline;
diff --git a/anime.min.js b/anime.min.js
index bc1b0de7..798892af 100644
--- a/anime.min.js
+++ b/anime.min.js
@@ -22,5 +22,5 @@ f.rgb(a)||f.hsl(a)}},q=function(){function a(a,d,b){return(((1-3*b+3*d)*a+(3*b-6
var m=a(k,c,b)-h,k=k-m/l}h=k}else if(0===l)h=k;else{var k=g,g=g+.1,n=0;do m=k+(g-k)/2,l=a(m,c,b)-h,0<l?g=m:k=m;while(1e-7<Math.abs(l)&&10>++n);h=m}return a(h,d,e)}}}}(),H=function(){function a(a,b){return 0===a||1===a?a:-Math.pow(2,10*(a-1))*Math.sin(2*(a-1-b/(2*Math.PI)*Math.asin(1))*Math.PI/b)}var c=" Quad Cubic Quart Quint Sine Expo Circ Back Elastic".split(" "),d={In:[[.42,0,1,1],[.55,.085,.68,.53],[.55,.055,.675,.19],[.895,.03,.685,.22],[.755,.05,.855,.06],[.47,0,.745,.715],[.95,.05,.795,.035],
[.6,.04,.98,.335],[.6,-.28,.735,.045],a],Out:[[0,0,.58,1],[.25,.46,.45,.94],[.215,.61,.355,1],[.165,.84,.44,1],[.23,1,.32,1],[.39,.575,.565,1],[.19,1,.22,1],[.075,.82,.165,1],[.175,.885,.32,1.275],function(b,c){return 1-a(1-b,c)}],InOut:[[.42,0,.58,1],[.455,.03,.515,.955],[.645,.045,.355,1],[.77,0,.175,1],[.86,0,.07,1],[.445,.05,.55,.95],[1,0,0,1],[.785,.135,.15,.86],[.68,-.55,.265,1.55],function(b,c){return.5>b?a(2*b,c)/2:1-a(-2*b+2,c)/2}]},b={linear:q(.25,.25,.75,.75),ease:q(.25,.1,.25,1)},e={},
g;for(g in d)e.type=g,d[e.type].forEach(function(a){return function(d,e){b["ease"+a.type+c[e]]=f.fnc(d)?d:q.apply($jscomp$this,d)}}(e)),e={type:e.type};return b}(),ba={css:function(a,c,d){return a.style[c]=d},attribute:function(a,c,d){return a.setAttribute(c,d)},object:function(a,c,d){return a[c]=d},transform:function(a,c,d,b,e){b[e]||(b[e]=[]);b[e].push(c+"("+d+")")}},J=[],m=[],v=0,fa=function(){function a(){v=requestAnimationFrame(c)}function c(c){if(m.length){for(var b=0;b<m.length;b++)m[b].tick(c);
-a()}else cancelAnimationFrame(v),v=0}return a}();l.version="2.0.0";l.speed=1;l.active=m;l.list=J;l.remove=function(a){a=F(a);for(var c=m.length-1;0<=c;c--)for(var d=m[c],b=d.animations,e=b.length-1;0<=e;e--)y(a,b[e].animatable.target)&&(b.splice(e,1),b.length||d.pause())};l.getValue=D;l.path=function(a,c){var d=f.str(a)?r(a)[0]:a,b=c||100;return function(a){return{el:d,property:a,totalLength:d.getTotalLength()*(b/100)}}};l.bezier=q;l.easings=H;l.timeline=function(a){a=void 0===a?{easing:"linear"}:
-a;var c=l(a);c.children=[];c.add=function(a){t(a).forEach(function(a){a.duration>c.duration&&(c.duration=a.duration);a.pause();c.children.push(a)})};return c};l.random=function(a,c){return Math.floor(Math.random()*(c-a+1))+a};return l});
\ No newline at end of file
+a()}else cancelAnimationFrame(v),v=0}return a}();l.version="2.0.0";l.speed=1;l.active=m;l.list=J;l.remove=function(a){a=F(a);for(var c=m.length-1;0<=c;c--)for(var d=m[c],b=d.animations,e=b.length-1;0<=e;e--)y(a,b[e].animatable.target)&&(b.splice(e,1),b.length||d.pause())};l.getValue=D;l.path=function(a,c){var d=f.str(a)?r(a)[0]:a,b=c||100;return function(a){return{el:d,property:a,totalLength:d.getTotalLength()*(b/100)}}};l.pathDashoffset=function(a){var c=a.getTotalLength();a.setAttribute("stroke-dasharray",
+c);return c};l.bezier=q;l.easings=H;l.timeline=function(a){a=void 0===a?{easing:"linear"}:a;var c=l(a);c.children=[];c.add=function(a){t(a).forEach(function(a){a.duration>c.duration&&(c.duration=a.duration);a.pause();c.children.push(a)})};return c};l.random=function(a,c){return Math.floor(Math.random()*(c-a+1))+a};return l});
\ No newline at end of file
diff --git a/documentation/examples/anime-logo-animation.html b/documentation/examples/anime-logo-animation.html
index 03b93f22..38d11df5 100644
--- a/documentation/examples/anime-logo-animation.html
+++ b/documentation/examples/anime-logo-animation.html
@@ -170,12 +170,6 @@
</div>
<script>
- function setDashoffset(el) {
- var l = el.getTotalLength();
- el.setAttribute('stroke-dasharray', l);
- return l;
- }
-
var logoAnimation = anime.timeline({
loop: false,
autoplay: true
@@ -212,7 +206,7 @@
var fillsIn = anime({
targets: '.fill.in',
strokeDashoffset: {
- value: [setDashoffset, 0],
+ value: [anime.pathDashoffset, 0],
duration: 600,
delay: function(el, i, t) { return 700 + ( i * 100 ); },
easing: 'easeOutQuart'
@@ -232,9 +226,9 @@
var fillsOut = anime({
targets: '.fill.out',
strokeDashoffset: [
- { value: [setDashoffset, setDashoffset], duration: 1890 },
+ { value: [anime.pathDashoffset, anime.pathDashoffset], duration: 1890 },
{
- value: [0, setDashoffset],
+ value: [0, anime.pathDashoffset],
duration: 800,
delay: function(el, i) { return (i * 80); },
easing: 'easeInQuart'
@@ -245,7 +239,7 @@
var linesOut = anime({
targets: '.line.out',
strokeDashoffset: {
- value: [0, setDashoffset],
+ value: [0, anime.pathDashoffset],
duration: 1200,
delay: function(el, i, t) { return 2500 + ( i * 100 ); },
easing: 'easeInQuart'
@@ -268,7 +262,7 @@
var iconLine = anime({
targets: '.icon-line',
strokeDashoffset: [
- { value: [setDashoffset, setDashoffset], duration: 3000 },
+ { value: [anime.pathDashoffset, anime.pathDashoffset], duration: 3000 },
{ value: 0, duration: 1200, easing: 'easeInOutQuart' }
],
stroke: {