bootstrap彈窗居中處理

1.第一種是修改bootstrap.js中的Modal.prototype.show 方法中添加如下一段代碼,這種方式模態框出現的很平滑,bug暫未出現css

/*模態框居中*/
var $dialog=that.$element.find("div.modal-dialog"),
top=(document.documentElement.clientHeight-$dialog.height())/2;
$dialog.css({"margin":+top+"px auto"});
/*---------*/bootstrap

 

2.第二種是在模態框出現以後,在出現彈窗後加入如下方法this

$('#addModal').on('shown.bs.modal', function(){
  var $this = $(this);
  var $modal_dialog = $this.find('.modal-dialog');
  var m_top = ( $(window).height() - $modal_dialog.height() )/2;
$modal_dialog.css({'margin': m_top + 'px auto'});
});prototype

相關文章
相關標籤/搜索