Created
December 19, 2014 01:21
-
-
Save giiska/33c5c797c76422a06cae to your computer and use it in GitHub Desktop.
Shortcut for adding animation class name to dom element
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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