Bootstrap3模态垂直居中


1     <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
2         <div class="modal-dialog modal-lg">
3             <div class="modal-content"></div><!-- /.modal-content -->
4         </div><!-- /.modal -->
5     </div>

1         function openDialog() {
2             var modal = $('#myModal').modal({ keyboard: false, backdrop: 'static'/*,remote: 'Detail?r=' + Math.random()*/ })
3             modal.find('.modal-content').load('Detail', { R: Math.random() });
4         }

1
$(function () { 2 function centerModals() { 3 $('#myModal').each(function (i) { 4 var $clone = $(this).clone().css('display', 'block').appendTo('body'); 5 var top = Math.round(($clone.height() - $clone.find('.modal-content').height()) / 2); 6 top = top > 0 ? top : 0; 7 $clone.remove(); 8 $(this).find('.modal-content').css("margin-top", top); 9 }); 10 } 11 if ($('#myModal').size() > 0) { 12 //$('#myModal').on('shown.bs.modal', centerModals); 13 //$(window).on('resize', centerModals); 14 setInterval(centerModals, 200); 15 } 16 });
原文地址:https://www.cnblogs.com/ToughGuy/p/4519980.html