Callback einer jQuery Funktion hinzufügen

Jan-Frederik Stieler

Monsterator
Moderator
Hi,
kann mir jemand vielleicht erklären wie man in jQuery einer Funktion ein Callback hinzufügt?
Ich habe diese Funktion um animate.css Klassen dynamisch hinzuzufügen udn bräuchte hier noch ein Callback wenn die Animation fertig ist.

Javascript:
$.fn.extend({
    animateCss: function (animationName) {
        var animationEnd = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend';
        $(this).addClass('animated ' + animationName).one(animationEnd, function() {
            $(this).removeClass('animated ' + animationName);
        });
    }
});
 
Sofern jQuery von der API her nichts dagegen hat, würde ich einfach einen zusätzlichen Callback-Parameter hinzufügen.
Javascript:
$.fn.extend({
    animateCss: function (animationName, endCallback) {
        var animationEnd = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend';
        $(this).addClass('animated ' + animationName).one(animationEnd, function() {
            $(this).removeClass('animated ' + animationName);
            if (endCalblack) {
              endCallback();
            }
        });
    }
});
 

Neue Beiträge

Zurück