问题:bootstrap的模态框默认是距离顶部30px,但是设计通常是居中的。
解决方法:
bootstrap提供了一个 show.bs.modal 的事件,代码如下
$(document).on('show.bs.modal','.modal',function(e){
var $this= $(this);
var $modal_dialog = $this.find('.modal-dialog');
$this.css('display', 'block');
$modal_dialog.css({'margin-top': Math.max(0, ($(window).height() - $modal_dialog.height()) / 2) });
});
另,这个方法在 bootbox里同样可以。 (还没用bootbox的看 这里 );
p: