Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2015
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. /**
  2. * Vertically center Bootstrap 3 modals so they aren't always stuck at the top
  3. */
  4. $(function() {
  5.  
  6. function reposition() {
  7.  
  8. var modal = $(this),
  9. dialog = modal.find('.modal-dialog');
  10.  
  11. modal.css('display', 'block');
  12.  
  13. // Dividing by two centers the modal exactly, but dividing by three
  14. // or four works better for larger screens.
  15. dialog.css("margin-top", Math.max(0, ($(window).height() - dialog.height()) / 2));
  16.  
  17. }
  18.  
  19. // Reposition when a modal is shown
  20. $('.modal').on('show.bs.modal', reposition);
  21.  
  22. // Reposition when the window is resized
  23. $(window).on('resize', function() {
  24. $('.modal:visible').each(reposition);
  25. });
  26.  
  27. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement