Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. <head>
  2. <meta name="viewport" content="width=device-width, initial-scale=1">
  3. <style>
  4. body {font-family: Arial, Helvetica, sans-serif;}
  5.  
  6. #myImg {
  7. border-radius: 5px;
  8. cursor: pointer;
  9. transition: 0.3s;
  10. }
  11.  
  12. #myImg:hover {opacity: 0.7;}
  13.  
  14. /* The Modal (background) */
  15. .modal {
  16. display: none; /* Hidden by default */
  17. position: fixed; /* Stay in place */
  18. z-index: 100; /* Sit on top */
  19. padding-top: 100px; /* Location of the box */
  20. left: 0;
  21. top: 0;
  22. width: 100%; /* Full width */
  23. height: 100%; /* Full height */
  24. overflow: auto; /* Enable scroll if needed */
  25. background-color: rgb(0,0,0); /* Fallback color */
  26. background-color: rgba(0,0,0,0.9); /* Black w/ opacity */
  27. }
  28.  
  29. /* Modal Content (image) */
  30. .modal-content {
  31. margin: auto;
  32. display: block;
  33. width: 80%;
  34. max-width: 700px;
  35. }
  36.  
  37. /* Caption of Modal Image */
  38. #caption {
  39. margin: auto;
  40. display: block;
  41. width: 80%;
  42. max-width: 700px;
  43. text-align: center;
  44. color: #ccc;
  45. padding: 10px 0;
  46. height: 150px;
  47. }
  48.  
  49. /* Add Animation */
  50. .modal-content, #caption {
  51. -webkit-animation-name: zoom;
  52. -webkit-animation-duration: 0.6s;
  53. animation-name: zoom;
  54. animation-duration: 0.6s;
  55. }
  56.  
  57. @-webkit-keyframes zoom {
  58. from {-webkit-transform:scale(0)}
  59. to {-webkit-transform:scale(1)}
  60. }
  61.  
  62. @keyframes zoom {
  63. from {transform:scale(0)}
  64. to {transform:scale(1)}
  65. }
  66.  
  67. /* The Close Button */
  68. .close {
  69. position: absolute;
  70. top: 15px;
  71. right: 35px;
  72. color: #f1f1f1;
  73. font-size: 40px;
  74. font-weight: bold;
  75. transition: 0.3s;
  76. }
  77.  
  78. .close:hover,
  79. .close:focus {
  80. color: #bbb;
  81. text-decoration: none;
  82. cursor: pointer;
  83. }
  84.  
  85. /* 100% Image Width on Smaller Screens */
  86. @media only screen and (max-width: 700px){
  87. .modal-content {
  88. width: 100%;
  89. }
  90. }
  91. </style>
  92. </head>
  93. <body>
  94.  
  95. <!-- Trigger/Open The Modal -->
  96. <a href="#"><text id="myBtn">Click Here To View</text></a>
  97.  
  98. <!-- The Modal -->
  99. <div id="myModal" class="modal">
  100. <span class="close">&times;</span>
  101. <img class="modal-content" src="/image.jpg" id="img01">
  102. <div id="caption"></div>
  103. </div>
  104.  
  105. <script>
  106. // Get the modal
  107. var modal = document.getElementById("myModal");
  108.  
  109. // Get the button that opens the modal
  110. var btn = document.getElementById("myBtn");
  111.  
  112. // Get the <span> element that closes the modal
  113. var span = document.getElementsByClassName("close")[0];
  114.  
  115. // When the user clicks the button, open the modal
  116. btn.onclick = function() {
  117. modal.style.display = "block";
  118. }
  119.  
  120. // When the user clicks on <span> (x), close the modal
  121. span.onclick = function() {
  122. modal.style.display = "none";
  123. }
  124.  
  125. // When the user clicks anywhere outside of the modal, close it
  126. window.onclick = function(event) {
  127. if (event.target == modal) {
  128. modal.style.display = "none";
  129. }
  130. }
  131. </script>
  132.  
  133. </body>
  134. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement