Skip to content

Instantly share code, notes, and snippets.

@aichholzer
Last active November 9, 2017 03:31
Show Gist options
  • Save aichholzer/fe7b2f1d24254a7ebee05cd3dc12d483 to your computer and use it in GitHub Desktop.
Save aichholzer/fe7b2f1d24254a7ebee05cd3dc12d483 to your computer and use it in GitHub Desktop.
Element animator for jQuery
/**
* Element fadeIn plugin for jQuery.
* @author Stefan Aichholzer <https://github.com/aichholzer>
* @param options -Object defining the animation's end result.
*
* {
* opacity: 1,
* marginBottom: 5,
* duration: 50
* }
*/
(function ($) {
$.fn.animator = function animator(options = null) {
if (!options) {
return this;
}
this.toArray()
.map(item => () => $(item).animate(options, options.duration).promise())
.reduce((current, next) => current.then(next), $().promise());
};
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment