Advertisement
TheiPhoneFan

Popup Box

May 4th, 2024 (edited)
786
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 3.60 KB | None | 0 0
  1. <!-- Created On 2024-05-04 -->
  2. <!DOCTYPE html>
  3. <html lang="en">
  4.  
  5. <head>
  6.     <!-- External Font -->
  7.     <link href="https://fonts.googleapis.com/css?family=Roboto:400,300,100,700,900" rel="stylesheet" type="text/css">
  8.     <link href='https://fonts.googleapis.com/css?family=Lora:400,300,100,700,900' rel='stylesheet'>
  9.     <!-- Stylesheet Link -->
  10.     <link rel="stylesheet" href="./theme/style.css" />
  11.     <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  12.     <!-- Favicon Image Link -->
  13.     <link rel="icon" type="image/x-png" href="./logos/js-blog-favicon.png">
  14.     <!-- Enables Unicode Characters To Be Displayed -->
  15.     <meta charset="UTF-8">
  16.     <!-- Scales Website Content -->
  17.     <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  18.     <title>Popup Boxes</title>
  19.     <style>
  20.         .popup {
  21.             position: fixed;
  22.             top: 50%;
  23.             left: 50%;
  24.             transform: translate(-50%, -50%);
  25.             background-color: #fff;
  26.             padding: 20px;
  27.             border: 2px solid gray;
  28.             border-radius: 16px;
  29.             max-width: 90%;
  30.             max-height: 90%;
  31.             overflow: auto;
  32.             z-index: 9999;
  33.         }
  34.  
  35.         .popup h1, h2, h3, p {
  36.             color: black;
  37.         }
  38.  
  39.         .overlay {
  40.             position: fixed;
  41.             top: 0;
  42.             left: 0;
  43.             width: 100%;
  44.             height: 100%;
  45.             background-color: rgba(0, 0, 0, 0.5);
  46.             z-index: 9998;
  47.         }
  48.  
  49.         .close-button {
  50.             position: absolute;
  51.             top: 10px;
  52.             right: 10px;
  53.             cursor: pointer;
  54.             font-size: 25px;
  55.         }
  56.  
  57.         .popup-button-img {
  58.             cursor: pointer;
  59.             border-radius: 16px;
  60.             width: 300px;
  61.             max-width: 100%;
  62.         }
  63.     </style>
  64. </head>
  65.  
  66. <body>
  67.     <div class="flex-container">
  68.         <div>
  69.             <img src="fish.jpg" onclick="openPopup('popup1')" class="popup-button-img">
  70.         </div>
  71.         <div>
  72.             <img src="flower.jpg" onclick="openPopup('popup2')" class="popup-button-img">
  73.         </div>
  74.     </div>
  75.  
  76.     <div id="popup1" class="popup" style="display: none;">
  77.         <span class="close-button" onclick="closePopup('popup1')">×</span>
  78.         <h2>Popup 1</h2>
  79.         <p>This is the content of Popup 1.</p>
  80.     </div>
  81.  
  82.     <div id="popup2" class="popup" style="display: none;">
  83.         <span class="close-button" onclick="closePopup('popup2')">×</span>
  84.         <h2>Popup 2</h2>
  85.         <p>This is the content of Popup 2.</p>
  86.     </div>
  87.  
  88.     <div id="overlay" class="overlay" style="display: none;"></div>
  89.  
  90.     <script>
  91.         function openPopup(popupId) {
  92.             var popup = document.getElementById(popupId);
  93.             var overlay = document.getElementById('overlay');
  94.             if (popup && overlay) {
  95.                popup.style.display = 'block';
  96.                 overlay.style.display = 'block';
  97.                 document.addEventListener('keydown', function(e) {
  98.                     if (e.key === 'Escape') {
  99.                         closePopup(popupId);
  100.                     }
  101.                 });
  102.             }
  103.         }
  104.  
  105.         function closePopup(popupId) {
  106.             var popup = document.getElementById(popupId);
  107.             var overlay = document.getElementById('overlay');
  108.             if (popup && overlay) {
  109.                popup.style.display = 'none';
  110.                 overlay.style.display = 'none';
  111.             }
  112.         }
  113.     </script>
  114.  
  115. </body>
  116.  
  117. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement