Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a callback called cleanup to do additional tasks before removing animations #458

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
7 changes: 6 additions & 1 deletion documentation/assets/js/anime/anime.2.2.0.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
begin: undefined,
run: undefined,
complete: undefined,
cleanup: undefined,
loop: 1,
direction: 'normal',
autoplay: true,
Expand Down Expand Up @@ -865,6 +866,10 @@
}
}

instance.cleaner = function () {
if(instance.cleanup != undefined) setCallback('cleanup')
}

instance.reset = function() {
const direction = instance.direction;
const loops = instance.loop;
Expand Down Expand Up @@ -988,7 +993,7 @@
anime.easings = easings;
anime.timeline = timeline;
anime.random = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;

return anime;

}));
8 changes: 7 additions & 1 deletion lib/anime.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ var defaultInstanceSettings = {
loop: 1,
direction: 'normal',
autoplay: true,
timelineOffset: 0
timelineOffset: 0,
cleanup: null
};

var defaultTweenSettings = {
Expand Down Expand Up @@ -1141,6 +1142,11 @@ function anime(params) {
instance.play();
};

instance.cleaner = function () {
if(instance.cleanup != null) { setCallback('cleanup'); }
};


instance.reset();

if (instance.autoplay) { instance.play(); }
Expand Down
15 changes: 10 additions & 5 deletions lib/anime.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ var defaultInstanceSettings = {
loop: 1,
direction: 'normal',
autoplay: true,
timelineOffset: 0
timelineOffset: 0,
cleanup: null
};

var defaultTweenSettings = {
Expand Down Expand Up @@ -242,7 +243,7 @@ var penner = (function () {
var a = minMax(amplitude, 1, 10);
var p = minMax(period, .1, 2);
return function (t) {
return (t === 0 || t === 1) ? t :
return (t === 0 || t === 1) ? t :
-a * Math.pow(2, 10 * (t - 1)) * Math.sin((((t - 1) - (p / (Math.PI * 2) * Math.asin(1 / a))) * (Math.PI * 2)) / p);
}
}
Expand All @@ -258,7 +259,7 @@ var penner = (function () {
var easeIn = functionEasings[name];
eases['easeIn' + name] = easeIn;
eases['easeOut' + name] = function (a, b) { return function (t) { return 1 - easeIn(a, b)(1 - t); }; };
eases['easeInOut' + name] = function (a, b) { return function (t) { return t < 0.5 ? easeIn(a, b)(t * 2) / 2 :
eases['easeInOut' + name] = function (a, b) { return function (t) { return t < 0.5 ? easeIn(a, b)(t * 2) / 2 :
1 - easeIn(a, b)(t * -2 + 2) / 2; }; };
});

Expand Down Expand Up @@ -515,7 +516,7 @@ function getRectLength(el) {

function getLineLength(el) {
return getDistance(
{x: getAttribute(el, 'x1'), y: getAttribute(el, 'y1')},
{x: getAttribute(el, 'x1'), y: getAttribute(el, 'y1')},
{x: getAttribute(el, 'x2'), y: getAttribute(el, 'y2')}
);
}
Expand Down Expand Up @@ -856,7 +857,7 @@ var pausedInstances = [];
var raf;

var engine = (function () {
function play() {
function play() {
raf = requestAnimationFrame(step);
}
function step(t) {
Expand Down Expand Up @@ -1143,6 +1144,10 @@ function anime(params) {
instance.play();
};

instance.cleaner = function () {
if(instance.cleanup != null) { setCallback('cleanup'); }
};

instance.reset();

if (instance.autoplay) { instance.play(); }
Expand Down
2 changes: 1 addition & 1 deletion lib/anime.min.js

Large diffs are not rendered by default.

Loading