彈框組件

來源:互聯網
上載者:User

標籤:dal   type   ons   pos   can   pac   add   color   cancel   

因為項目中使用的較多,因此封裝了一個組件,便於使用。

/**@file 彈框組件*@description 用於所有提示彈框*@time 2016/11/29*/function PopModel(options) {    var that = this;    this.defaults = {           width: ‘100px‘, // 預設框          height: ‘120px‘, // 預設高          isMask: true, // 是否遮罩             dir: ‘mid‘, // mid中間,left左下,right右下        addClass: ‘‘, // 設定不同樣式的class        headHtml: ‘<button type="button" class="close">關閉</button>‘, // 頭部,不需要直接設定為空白        bodyHtml: ‘‘,// 內容        footHtml: ‘<input type="button" value="確定" class="confirm"><input type="button" value="取消" class="cancel">‘,// 底部,不需要直接設定為空白        confireFn: function () {}, // 確認回調         cancelFn: function () {} // 取消回調    };    this.opts = $.extend({}, this.defaults, options);    this.dialogWrap = $(‘<div class="dialog-wrap">‘);    this.modal = $(‘<div class="qbb-dialog ‘ + this.opts.addClass + ‘" style="position:fixed;border-radius:5px;background:#fff;z-index:99999;width:‘+ this.opts.width+‘;height:‘+ this.opts.height+‘">‘);    this.header = $(‘<div class="modal-header">‘);    this.obody = $(‘<div class="modal-body">‘);    this.footer = $(‘<div class="modal-footer">‘);    this.mask = $(‘<div class="mask" style="position:fixed;left:0;top:0;width:100%;height:100%;z-index:9999;background:#000;opacity:0.5">‘); // 遮罩    this.objDir(this.modal, this.opts.dir);    if (this.opts.headHtml != ‘‘) {        this.header.append(this.opts.headHtml);        this.modal.append(this.header);    }    if (this.opts.bodyHtml != ‘‘) {        this.obody.append(this.opts.bodyHtml);        this.modal.append(this.obody);    }    if (this.opts.footHtml != ‘‘) {        this.footer.append(this.opts.footHtml);        this.modal.append(this.footer);    }    if (this.opts.isMask) {        $(this.dialogWrap).append(this.mask);    }    this.dialogWrap.append(this.modal);    $(‘body‘).append(this.dialogWrap);        $(document).on(‘click‘, ‘.mask, .dialog-wrap .close‘, function () {        that.closeFn();    });        $(this.footer).find(‘.confirm‘).on(‘click‘, function() {        that.opts.confireFn();        that.closeFn();    });    $(this.footer).find(‘.cancel‘).on(‘click‘, function() {        that.opts.cancelFn();        that.closeFn();    })}PopModel.prototype = {    constructor: PopModel,        // 關閉函數    closeFn: function () {       this.dialogWrap.remove();    },        // 位置函數    objDir: function (o, dir) {        var w = $(o).outerWidth(true);        var h = $(o).outerHeight(true);        var winW = $(window).width();        var winH = $(window).height();        var oTop = ( winH - h )/2;        var oLeft = ( winW - w )/2;        if (dir == ‘mid‘) {            $(o).css({‘left‘:oLeft, ‘top‘:oTop});        } else if (dir == ‘left‘) {            $(o).css({‘left‘:0, ‘bottom‘:0});        } else if (dir == ‘right‘) {            $(o).css({‘right‘:0, ‘bottom‘:0});        }    }}

調用:

new PopModel({});

彈框組件

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.