Skip to content

Instantly share code, notes, and snippets.

@raecoo
Created July 12, 2014 03:34
Show Gist options
  • Save raecoo/abf3e03f89aa421706f6 to your computer and use it in GitHub Desktop.
Save raecoo/abf3e03f89aa421706f6 to your computer and use it in GitHub Desktop.
Bootstrap Modal Vertically Center
function centerModal() {
$(this).css('display', 'block');
var $dialog = $(this).find(".modal-dialog");
var offset = ($(window).height() - $dialog.height()) / 2;
// Center modal vertically in window
$dialog.css("margin-top", offset);
}
$('.modal').on('show.bs.modal', centerModal);
$(window).on("resize", function () {
$('.modal:visible').each(centerModal);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment