Skip to content

Instantly share code, notes, and snippets.

@mtetlow
Created March 17, 2014 15:37
Show Gist options
  • Save mtetlow/9601548 to your computer and use it in GitHub Desktop.
Save mtetlow/9601548 to your computer and use it in GitHub Desktop.
bootstrap modal centering and resizing
$j('.modal').on('show.bs.modal', function(e) {
var modal = $j(this);
var modalContent = $j(this).find('.modal-content');
var modalDialog = $j(this).find('.modal-dialog');
//If the modal is too tall, resize it
if($j(modalDialog).height()>=$j(window).height()){
$j(modalDialog).height($j(window).height()-20);
}
//If the modal is too wide, resize it
if($j(modalDialog).width()>=$j(window).width()){
$j(modalDialog).width($j(window).width()-20);
}
//Vertically center the modal
$j(modalDialog).css('margin-top',($j(window).height()-$j(modalDialog).height())/2+'px');
return this;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment