Click Function on jQuery plugin only allows for single click

Posted by user1427307 on Stack Overflow See other posts from Stack Overflow or by user1427307
Published on 2012-06-02T16:34:41Z Indexed on 2012/06/02 16:40 UTC
Read the original article Hit count: 183

Filed under:
|
|

I've created this simple plugin to add multiple animations on click but the problem is that once the object is clicked it can not repeat the animation by clicking again, i can't figure out why the added class is not removing itself after the click function is complete to allow it to be clicked again and repeat.. any suggestions?

(function($) {
    $.fn.vivify = function(options) {
        var defaults = {
            animation: 'bounce',
        };
        var options = $.extend(defaults, options);
        return this.each(function() {
            var o = options;
            var obj = $(this);
            var animation = o.animation;
            obj.bind("click", function() {
                obj.addClass(o.animation);
                obj.addClass('vivify');
            }, function() {
                obj.removeClass(o.animation);
            });
        })
    }
})(jQuery);?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery