'use strict';
var elements = require('../elements');
var _animate = /** @function
* @param element
* @param animations
* @param options */function _animate(element, animations, options) {
var $element = elements(element);
if (!$element._animations) {
$element._animations = [];
}
var animationPlayer = element.animate(animations, options);
$element._animations.push(animationPlayer);
animationPlayer.addEventListener('finish', /** @function */function () {
var index = $element._animations.indexOf(element);
$element._animations.splice(index, 1);
if ($element._animations.length === 0) {
$element.fire(new Event('animationsFinished'));
}
});
return animationPlayer;
};
/**
* Animate
*
* @name Element#animate
* @method
* @param {Object} options
* @return {Element}
*/
elements.addMethodWithArgumentsReturnThis('animate', _animate);
/**
* Animate the opacity from 0 to 1
* @name Element#fadeOut
* @method
* @param {Object} options
* @return {AnimationPlayer}
*/
elements.addMethodWithArgumentsReturnThis('fadeOut', function (element, options) {
elements.setStyle(element, 'opacity', 0);
return _animate(element, [{ opacity: 1 }, { opacity: 0 }], options);
});
/**
* Animate the opacity from 1 to 0
* @name Element#fadeIn
* @method
* @param {Object} options
* @return {AnimationPlayer}
*/
elements.addMethodWithArgumentsReturnThis('fadeIn', function (element, options) {
elements.setStyle(element, 'opacity', 1);
return _animate(element, [{ opacity: 0 }, { opacity: 1 }], options);
});
/**
* Stop any animations for the element
* @name Element#stop
* @method
* @param {HTMLElement} element
* @param {Object} options
* @return {AnimationPlayer}
*/
elements.addMethodWithArgumentsReturnThis('stop', function (element, options) {
var $element = elements(element);
if (!$element._animations) {
return;
}
$element._animations.forEach(function (animationPlayer) {
return animationPlayer.finish();
});
});
//# sourceMappingURL=animations.js.map |