Advertisement
Guest User

Untitled

a guest
Feb 17th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. HTML:
  2.  
  3. <!--MODALS BEGIN HERE------------------>
  4.  
  5. <div id="new-post-modal" class="modalDialog">
  6. <div> <a href="#close" title="Close" class="close">&times;</a>
  7. <div class="modal-header">
  8. <div class="modal-content" id=modal-header>
  9. <h2>New Post</h2>
  10. </div>
  11. </div>
  12. <div class="modal-body">
  13. <div class="modal-content">
  14. <p>This is a sample modal box that can be created using the powers of CSS3.</p>
  15. <p>You could do a lot of things here like have a pop-up ad that shows when your website loads, or create a login/register form for users.</p>
  16. </div>
  17. </div>
  18. <div class="modal-footer">
  19. <div class="modal-content">
  20. <a>Make sure to include enough details in your post!</a>
  21. </div>
  22.  
  23. </div>
  24.  
  25.  
  26.  
  27.  
  28.  
  29. </div>
  30. </div>
  31.  
  32. <!----------SEPERATOR-------------->
  33.  
  34. <div id="sign-in-modal" class="modalDialog">
  35. <div> <a href="#close" title="Close" class="close">&times;</a>
  36. <div class="modal-header">
  37. <div class="modal-content" id=modal-header>
  38. <h2>Sign In</h2>
  39. </div>
  40. </div>
  41. <div class="modal-body">
  42. <div class="modal-content">
  43. <p>This is a sample modal box that can be created using the powers of CSS3.</p>
  44. <p>You could do a lot of things here like have a pop-up ad that shows when your website loads, or create a login/register form for users.</p>
  45. </div>
  46. </div>
  47. <div class="modal-footer">
  48. <div class="modal-content">
  49. <a href="http://www.frostburg.edu/computing/get-connected/password-management/">Forgot your password or having login issues?</a>
  50. </div>
  51.  
  52. </div>
  53. </div>
  54. </div>
  55.  
  56.  
  57.  
  58. JS:
  59.  
  60. //CODE TO CLOSE MODAL IF USER CLICKS OUTSIDE OR PRESSES ESC
  61. function modalClose() {
  62. if (location.hash == '#new-post-modal' || location.hash == '#sign-in-modal') {
  63. location.hash = '';
  64. }
  65. }
  66.  
  67. document.addEventListener('keyup', function(e) {
  68. if (e.keyCode == 27) {
  69. modalClose();
  70. }
  71. });
  72.  
  73. var modal = document.querySelector('#new-post-modal', '#sign-in-modal');
  74. modal.addEventListener('click', function(e) {
  75. modalClose();
  76. }, false);
  77.  
  78. modal.children[0].addEventListener('click', function(e) {
  79. e.stopPropagation();
  80. }, false);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement