Guest User

Copied lightbox code

a guest
Oct 21st, 2025
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Day 69</title>
  7. <style>
  8. * {
  9. padding: 0;
  10. margin: 0;
  11. box-sizing: border-box;
  12. }
  13.  
  14. body {
  15. background: #f4f4f9;
  16. display: flex;
  17. align-items: center;
  18. justify-content: center;
  19. height: 100vh;
  20. color: #333;
  21. }
  22.  
  23. img {
  24. width: 100%;
  25. height: auto;
  26. }
  27.  
  28. .gallery {
  29. display: grid;
  30. grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  31. gap: 15px;
  32. max-width: 800px;
  33. }
  34.  
  35. .galleryItem {
  36. border-radius: 8px;
  37. overflow: hidden;
  38. box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
  39. }
  40. .galleryItem img {
  41. width: 100%;
  42. height: 100%;
  43. -o-object-fit: cover;
  44. object-fit: cover;
  45. cursor: pointer;
  46. transition: 0.3s ease-in-out;
  47. }
  48. .galleryItem:hover img {
  49. transform: scale(1.1);
  50. }
  51.  
  52. #lightBox {
  53. display: none;
  54. align-items: center;
  55. justify-content: center;
  56. height: 100vh;
  57. position: fixed;
  58. left: 0;
  59. top: 0;
  60. background: rgba(0, 0, 0, 0.9);
  61. width: 100%;
  62. flex-direction: column;
  63. }
  64. #lightBox img {
  65. width: 90%;
  66. max-width: 560px;
  67. height: 80%;
  68. max-height: 500px;
  69. border-radius: 8px;
  70. -o-object-fit: cover;
  71. object-fit: cover;
  72. }
  73. #lightBox #close {
  74. position: absolute;
  75. top: 20px;
  76. right: 30px;
  77. color: #fff;
  78. cursor: pointer;
  79. font-size: 50px;
  80. }
  81. #lightBox #caption {
  82. color: #fff;
  83. margin-top: 20px;
  84. font-size: 1.1em;
  85. text-align: center;
  86. } /*# sourceMappingURL=style.css.map */
  87. </style>
  88. </head>
  89. <body>
  90. <div class="gallery">
  91. <div class="galleryItem">
  92. <img src="https://media.tenor.com/_zWYqfZdneIAAAAM/shocked-face-shocked-meme.gif" alt="Imagem 1" />
  93. </div>
  94.  
  95. <div class="galleryItem">
  96. <img src="https://www.bu.edu/files/2024/12/Screenshot-2024-12-13-at-12.42.40%E2%80%AFPM.png" alt="Imagem 2" />
  97. </div>
  98.  
  99. <div class="galleryItem">
  100. <img src="https://ichef.bbci.co.uk/images/ic/480xn/p0kbsfp5.jpg" alt="Imagem 3" />
  101. </div>
  102.  
  103.  
  104. </div>
  105.  
  106. <div id="lightBox">
  107. <span id="close">&times;</span>
  108. <img src="img/06.avif" alt="" id="lightBoxCon">
  109. <div id="caption">Image</div>
  110. </div>
  111.  
  112. <script>
  113. const galleryItems = document.querySelectorAll('.galleryItem img');
  114. const lightBox = document.getElementById('lightBox');
  115. const lightBoxImg = document.getElementById('lightBoxCon');
  116. const caption = document.getElementById('caption');
  117. const close = document.getElementById('close');
  118.  
  119. galleryItems.forEach(item => {
  120. item.addEventListener('click', ()=>{
  121.  
  122. lightBox.style.display = 'flex';
  123. lightBoxImg.src = item.src;
  124. caption.innerText = item.alt;
  125.  
  126.  
  127. })
  128.  
  129. close.addEventListener('click', (e)=>{
  130. lightBox.style.display = 'none';
  131. })
  132.  
  133. lightBox.addEventListener('click', (e)=>{
  134. if(e.target !== lightBoxImg && e.target !== caption){
  135. lightBox.style.display = 'none';
  136. }
  137. })
  138. })
  139. </script>
  140. </body>
  141. </html>
Advertisement
Add Comment
Please, Sign In to add comment