The jQuery solution, given the modal dialog, is an absolute / relative / fixed position:
var windowHeight = $(window).height();
var windowWidth = $(window).width();
var boxHeight = $('.modal-dialog').height();
var boxWidth = $('.modal-dialog').width();
$('.modal-dialog').css({'left' : ((windowWidth - boxWidth)/2), 'top' : ((windowHeight - boxHeight)/2)});
JQuery's solution, given the modal dialog, it does not set absolute / relative / fixed:
CSS
margin-left: auto;
margin-right: auto;
JQuery
var windowHeight = $(window).height();
var boxHeight = $('.modal-dialog').height();
$('.modal-dialog').css({'margin-top' : ((windowHeight - boxHeight )/2)});
source
share