Created
July 12, 2014 03:34
-
-
Save raecoo/abf3e03f89aa421706f6 to your computer and use it in GitHub Desktop.
Bootstrap Modal Vertically Center
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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