用完整的jquery函数编写

时间:2013-11-19 16:38:55

标签: javascript jquery function plugins

我正在尝试编写一个简单的jQuery函数来显示页面警报。但我希望能够在有多个警报的情况下对警报进行排序。我无法弄清楚如何使警报一次运行一个,并在前一个警报完成时触发每个警报。这是我到目前为止所拥有的。

$.softPageAlert = function(message,options) {
        other = $('div[rel=soft_page_alert]').last();
        me = $('<div rel="soft_page_alert"></div>');
        $("body").append(me);
        var span = $('<span></span>');
        me.empty().append(span);

        $.extend(me,{
            message : message,
            isComplete : false,
            settings : {
                messageType : '', // success (green), error(red), ... other settings
            },
            run : function(){
                me._init();
                console.log('triggering message: ' + me.message);
                me.fadeTo(  
                    me.settings.transitionSpeed,    // durration
                    me.settings.opacity,            // opacity
                    function(){                     // complete
                        setTimeout( 
                            me._off(),                  // complete
                            me.settings.displayTime     // durration
                        );
                    }
                );
            },
            _off : function(){
                me.fadeOut(
                    me.settings.transitionSpeed,    // durration
                    function(){                     // complete
                        me.isComplete = true;
                        me.complete()
                    }
                );
            },
            _init : function(){
                // set the CSS attributes for the alert box
                $.extend(me.settings,options);
                ... build the html and css
            },
            complete : function() {}
        });

        if ( (other.length > 0) && (other.isComplete == false) ) {
            console.log('Another');
            other.complete = function(){ me.run() };
        }else{
            console.log('No others');
            me.run();
        }

        return me;

    };

0 个答案:

没有答案