Bootstrap 模态框上下居中

在bootstrap.js里面找到Modal.prototype.adjustDialog在里面添加:

      // 是弹出框居中。。。
      var $modal_dialog = $(this.$element[0]).find('.modal-dialog');
      var m_top = ($(window).height() - $modal_dialog.height()) / 2;
      $modal_dialog.css({ 'margin': m_top + 'px auto' });

红色是需要添加的代码:

  Modal.prototype.adjustDialog = function () {
    var modalIsOverflowing = this.$element[0].scrollHeight > document.documentElement.clientHeight

    this.$element.css({
      paddingLeft:  !this.bodyIsOverflowing && modalIsOverflowing ? this.scrollbarWidth : '',
      paddingRight: this.bodyIsOverflowing && !modalIsOverflowing ? this.scrollbarWidth : ''
    })
      // 是弹出框居中。。。
      var $modal_dialog = $(this.$element[0]).find('.modal-dialog');
      var m_top = ($(window).height() - $modal_dialog.height()) / 2;
      $modal_dialog.css({ 'margin': m_top + 'px auto' });
  }
原文地址:https://www.cnblogs.com/xinbaba/p/9479462.html