cione-comp-lib
Version:
`$ yarn add cione-comp-lib` 或者 `$ npm i cione-comp-lib -S`
54 lines (53 loc) • 1.33 kB
JavaScript
var AnimationWrap = function() {
function AnimationWrap2() {
this._storage = [];
this._elExistsMap = {};
}
AnimationWrap2.prototype.add = function(el, target, duration, delay, easing) {
if (this._elExistsMap[el.id]) {
return false;
}
this._elExistsMap[el.id] = true;
this._storage.push({
el,
target,
duration,
delay,
easing
});
return true;
};
AnimationWrap2.prototype.finished = function(callback) {
this._finishedCallback = callback;
return this;
};
AnimationWrap2.prototype.start = function() {
var _this = this;
var count = this._storage.length;
var checkTerminate = function() {
count--;
if (count <= 0) {
_this._storage.length = 0;
_this._elExistsMap = {};
_this._finishedCallback && _this._finishedCallback();
}
};
for (var i = 0, len = this._storage.length; i < len; i++) {
var item = this._storage[i];
item.el.animateTo(item.target, {
duration: item.duration,
delay: item.delay,
easing: item.easing,
setToFinal: true,
done: checkTerminate,
aborted: checkTerminate
});
}
return this;
};
return AnimationWrap2;
}();
function createWrap() {
return new AnimationWrap();
}
export { createWrap };