Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [CSS][Java][PHP]Otwieranie zdjęć w osobnym oknie
david8213
post 22.03.2020, 08:07:18
Post #1





Grupa: Zarejestrowani
Postów: 308
Pomógł: 0
Dołączył: 9.12.2009

Ostrzeżenie: (10%)
X----


Czy można zastosować tą funkcję dal kilkunastu zdjęć czy trzeba dla każdego zdjęcia robić nową funkcję ?

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <style>
  5. #myImg {
  6. border-radius: 5px;
  7. cursor: pointer;
  8. transition: 0.3s;
  9. }
  10.  
  11. #myImg:hover {opacity: 0.7;}
  12.  
  13. /* The Modal (background) */
  14. .modal {
  15. display: none; /* Hidden by default */
  16. position: fixed; /* Stay in place */
  17. z-index: 1; /* Sit on top */
  18. padding-top: 100px; /* Location of the box */
  19. left: 0;
  20. top: 0;
  21. width: 100%; /* Full width */
  22. height: 100%; /* Full height */
  23. overflow: auto; /* Enable scroll if needed */
  24. background-color: rgb(0,0,0); /* Fallback color */
  25. background-color: rgba(0,0,0,0.9); /* Black w/ opacity */
  26. }
  27.  
  28. /* Modal Content (image) */
  29. .modal-content {
  30. margin: auto;
  31. display: block;
  32. width: 80%;
  33. max-width: 700px;
  34. }
  35.  
  36. /* Caption of Modal Image */
  37. #caption {
  38. margin: auto;
  39. display: block;
  40. width: 80%;
  41. max-width: 700px;
  42. text-align: center;
  43. color: #ccc;
  44. padding: 10px 0;
  45. height: 150px;
  46. }
  47.  
  48. /* Add Animation */
  49. .modal-content, #caption {
  50. -webkit-animation-name: zoom;
  51. -webkit-animation-duration: 0.6s;
  52. animation-name: zoom;
  53. animation-duration: 0.6s;
  54. }
  55.  
  56. @-webkit-keyframes zoom {
  57. from {-webkit-transform: scale(0)}
  58. to {-webkit-transform: scale(1)}
  59. }
  60.  
  61. @keyframes zoom {
  62. from {transform: scale(0.1)}
  63. to {transform: scale(1)}
  64. }
  65.  
  66. /* The Close Button */
  67. .close {
  68. position: absolute;
  69. top: 15px;
  70. right: 35px;
  71. color: #f1f1f1;
  72. font-size: 40px;
  73. font-weight: bold;
  74. transition: 0.3s;
  75. }
  76.  
  77. .close:hover,
  78. .close:focus {
  79. color: #bbb;
  80. text-decoration: none;
  81. cursor: pointer;
  82. }
  83.  
  84. /* 100% Image Width on Smaller Screens */
  85. @media only screen and (max-width: 700px){
  86. .modal-content {
  87. width: 100%;
  88. }
  89. }
  90. </style>
  91. </head>
  92. <body>
  93.  
  94.  
  95. <img id="myImg" src="03.jpeg" alt="Northern Lights, Norway" width="300" height="200">
  96. <img id="myImg" src="04.jpeg" alt="Northern Lights, Norway" width="300" height="200">
  97. <img id="myImg" src="05.jpeg" alt="Northern Lights, Norway" width="300" height="200">
  98. <img id="myImg" src="06.jpeg" alt="Northern Lights, Norway" width="300" height="200">
  99. <img id="myImg" src="07.jpeg" alt="Northern Lights, Norway" width="300" height="200">
  100. <img id="myImg" src="08.jpeg" alt="Northern Lights, Norway" width="300" height="200">
  101. <img id="myImg" src="09.jpeg" alt="Northern Lights, Norway" width="300" height="200">
  102.  
  103. <!-- The Modal -->
  104. <div id="myModal" class="modal">
  105. <span class="close">×</span>
  106. <img class="modal-content" id="img01">
  107. <div id="caption"></div>
  108. </div>
  109.  
  110.  
  111.  
  112.  
  113. <script>
  114. // Get the modal
  115. var modal = document.getElementById('myModal');
  116.  
  117. // Get the image and insert it inside the modal - use its "alt" text as a caption
  118. var img = document.getElementById('myImg');
  119. var modalImg = document.getElementById("img01");
  120. var captionText = document.getElementById("caption");
  121. img.onclick = function(){
  122. modal.style.display = "block";
  123. modalImg.src = this.src;
  124. modalImg.alt = this.alt;
  125. captionText.innerHTML = this.alt;
  126. }
  127.  
  128. // Get the <span> element that closes the modal
  129. var span = document.getElementsByClassName("close")[0];
  130.  
  131. // When the user clicks on <span> (x), close the modal
  132. span.onclick = function() {
  133. modal.style.display = "none";
  134. }
  135. </script>
  136.  
  137. </body>
  138. </html>
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 26.04.2024 - 11:10