码迷,mamicode.com
首页 > 其他好文 > 详细

bootstrap弹出框居中

时间:2016-11-08 07:42:52      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:display   height   mod   res   居中   visible   top   dia   vertica   

/**
* Vertically center Bootstrap 3 modals so they aren‘t always stuck at the top
*/
$(function() {
function reposition() {
var modal = $(this),
dialog = modal.find(‘.modal-dialog‘);
modal.css(‘display‘, ‘block‘);

// Dividing by two centers the modal exactly, but dividing by three
// or four works better for larger screens.
dialog.css("margin-top", Math.max(0, ($(window).height() - dialog.height()) / 2));
}
// Reposition when a modal is shown
$(‘.modal‘).on(‘show.bs.modal‘, reposition);
// Reposition when the window is resized
$(window).on(‘resize‘, function() {
$(‘.modal:visible‘).each(reposition);
});
});

bootstrap弹出框居中

标签:display   height   mod   res   居中   visible   top   dia   vertica   

原文地址:http://www.cnblogs.com/honghong87/p/6041262.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!