开发者

Call jQuery function within function

I have a jQuery function (stripped down just for this example):

(function($) {

    $.fn.Lightbox = function(options) {

       var opts = $.extend(defaults, options);

    开发者_运维问答    function initialize() {
            $('#lightbox').show();
            return false;
        };

        function close() {
            $('#lightbox').hide();
        };

        return this.click(initialize);
    };

})(jQuery);

I then use....

$('a.image').Lightbox();

to run it. I want to be able to call the close() function seperately e.g.

$.Lightbox.close();

How can I achieve this within my code?


You can add a method for that, like this:

(function($) {
    $.fn.Lightbox = function(options) {
       var opts = $.extend(defaults, options);

        function initialize() {
            $('#lightbox').show();
            return false;
        };

        function close() {
            $('#lightbox').hide();
        };
        return this.click(initialize);
    };    
    $.Lightbox = {
        close: function() {
            $('#lightbox').hide();
        }
    };
})(jQuery);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜