Skip to content

Instantly share code, notes, and snippets.

@giiska
Created December 19, 2014 01:21
Show Gist options
  • Save giiska/33c5c797c76422a06cae to your computer and use it in GitHub Desktop.
Save giiska/33c5c797c76422a06cae to your computer and use it in GitHub Desktop.
Shortcut for adding animation class name to dom element
/**
* Shortcut for adding animation class name to dom element
* @param {string} cls class name
* @param {Function} cb callback
* @param {Function} lastItemCb callback execute at last elment animated
* @return {object} this
*/
$.fn.classAnimoEnd = function(cls, cb, lastItemCb) {
var el = this;
cb && (cb = $.proxy(cb, el));
var count = $(el).length;
$(el)
.removeClass('animated ' + cls)
.one($.support.animate.end, function () {
cb && cb();
$(el).removeClass('animated');
if(count > 1) {
count --;
if(count === 0)
lastItemCb && lastItemCb();
}
})
.addClass('animated ' + cls);
if(!$(el).css('display') !== 'none' )
$(el).show();
return this;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment