Skip to content

Instantly share code, notes, and snippets.

@huobazi
Created November 20, 2014 07:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save huobazi/b9e335523ea5602a367d to your computer and use it in GitHub Desktop.
Save huobazi/b9e335523ea5602a367d to your computer and use it in GitHub Desktop.
bootstrap modal center
var setCenterModal = function () {
$(this).css('display', 'block');
var $dialog = $(this).find(".modal-dialog");
var offset = ($(window).height() - $dialog.height()) / 2;
$dialog.css("margin-top", offset);
};
$('.modal').on('show.bs.modal', setCenterModal);
$(window).on("resize", function () {
$('.modal:visible').each(setCenterModal);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment