公共弹窗js写法:Dialog.js

function Dialog(bg,els,opts) {
    this.$els = $(els);
    this.$Dialogbg = $(bg);
    this.$close = this.$els.find(opts.close);
    this.$btn = this.$els.find(opts.btn);
    this._init();
}
Dialog.prototype={
    _init:function () {
        var self = this;
        this.show();
        this.$Dialogbg.click(function () {
            self.hide();
        });
        this.$close.click(function () {
            self.hide();
        });
        this.$btn.click(function () {
            self.hide();
        });
    },
    show:function () {
        this.$Dialogbg.fadeIn(300);
        this.$els.fadeIn(300);
    },
    hide:function () {
        this.$Dialogbg.fadeOut(300);
        this.$els.fadeOut(300);
    }
};

/*实例化*/
new Dialog(".Dialogbg",'.DialogBox',{
    close:'.closes',
    btn:'.go-use'
});

 

 

给心灵一个纯净空间,让思想,情感,飞扬!