Jump to content

Modal trubles


frunzapavel1990

Recommended Posts

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {font-family: Arial, Helvetica, sans-serif;}

#myImg {
  border-radius: 5px;
  cursor: pointer;
  transition: 0.3s;
}

#myImg:hover {opacity: 0.7;}

/* The Modal (background) */
.modal {
  display: none; /* Hidden by default */
  position: fixed; /* Stay in place */
  z-index: 1; /* Sit on top */
  padding-top: 100px; /* Location of the box */
  left: 0;
  top: 0;
  width: 100%; /* Full width */
  height: 100%; /* Full height */
  overflow: auto; /* Enable scroll if needed */
  background-color: rgb(0,0,0); /* Fallback color */
  background-color: rgba(0,0,0,0.9); /* Black w/ opacity */
}

/* Modal Content (image) */
.modal-content {
  margin: auto;
  display: block;
  width: 700px;
  max-width: 700px;
  height: 700px;
  max-height: 700px;
}

/* Caption of Modal Image */
#caption {
  margin: auto;
  display: block;
  width: 80%;
  max-width: 700px;
  text-align: center;
  color: #ccc;
  padding: 10px 0;
  height: 150px;
}

/* Add Animation */
.modal-content, #caption {  
  -webkit-animation-name: zoom;
  -webkit-animation-duration: 0.6s;
  animation-name: zoom;
  animation-duration: 0.6s;
}

@-webkit-keyframes zoom {
  from {-webkit-transform:scale(0)} 
  to {-webkit-transform:scale(1)}
}

@keyframes zoom {
  from {transform:scale(0)} 
  to {transform:scale(1)}
}

/* The Close Button */
.close {
  position: absolute;
  top: 15px;
  right: 35px;
  color: #000000;
  font-size: 40px;
  font-weight: bold;
  transition: 0.3s;
}

.close:hover,
.close:focus {
  color: #bbb;
  text-decoration: none;
  cursor: pointer;
}

/* 100% Image Width on Smaller Screens */
@media only screen and (max-width: 700px){
  .modal-content {
    width: 100%;
  }
}
</style>
</head>
<body>

<img id="myImg0" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/108161358_177264987148565_453099730794799976_o_480x480.jpg?v=1594620948" alt="" width="300" height="300" >
<img id="myImg1" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/107968188_177264947148569_5820408219925839830_o_480x480.jpg?v=1594620974" alt="" width="300" height="300">
<img id="myImg2" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/107910973_177264917148572_5111055440654314917_o_480x480.jpg?v=1594620996" alt="" width="300" height="300">
<img id="myImg3" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/107635356_177264870481910_7112395107561359045_o_480x480.jpg?v=1594621016" alt="" width="300" height="300">
<img id="myImg4" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/br-1_480x480.jpg?v=1594704608" alt="" width="300" height="300">
<img id="myImg5" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/br_1_480x480.jpg?v=1594704635" alt="" width="300" height="300">
<img id="myImg6" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/br-2_480x480.jpg?v=1594704654" alt="" width="300" height="300">
<img id="myImg7" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/br-10_480x480.jpg?v=1594704974" alt="" width="300" height="300">
<img id="myImg8" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/br-11_480x480.jpg?v=1594704992" alt="" width="300" height="300">
<img id="myImg9" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/br-12_480x480.jpg?v=1594705011" alt="" width="300" height="300">
<img id="myImg10" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/br-13_480x480.jpg?v=1594705032" alt="" width="300" height="300">
<img id="myImg11" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/br-14_480x480.jpg?v=1594705050" alt="" width="300" height="300">
<img id="myImg12" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/gl-1_480x480.jpg?v=1594705066" alt="" width="300" height="300">
<img id="myImg13" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/gl-2_480x480.jpg?v=1594705083" alt="" width="300" height="300">
<img id="myImg14" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/gl-3_480x480.jpg?v=1594705098" alt="" width="300" height="300">
<img id="myImg15" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/gl-4_480x480.jpg?v=1594705116" alt="" width="300" height="300">
<img id="myImg16" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/gl-5_480x480.jpg?v=1594705135" alt="" width="300" height="300">
<img id="myImg17" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/gl-6_480x480.jpg?v=1594705181" alt="" width="300" height="300">
<img id="myImg18" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/gl-7_480x480.jpg?v=1594705199" alt="" width="300" height="300">
<img id="myImg19" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/gl-8_480x480.jpg?v=1594705216" alt="" width="300" height="300">
<img id="myImg20" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/br-3_480x480.jpg?v=1594704673" alt="" width="300" height="300">
<img id="myImg21" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/br-4_480x480.jpg?v=1594704697" alt="" width="300" height="300">
<img id="myImg22" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/br-6_480x480.jpg?v=1594704722" alt="" width="300" height="300">
<img id="myImg23" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/br-7_480x480.jpg?v=1594704739" alt="" width="300" height="300">
<img id="myImg24" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/br-8_480x480.jpg?v=1594704765" alt="" width="300" height="300">
<img id="myImg25" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/br-9_480x480.jpg?v=1594704789" alt="" width="300" height="300">
<img id="myImg26" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/84474535_772995926525464_4417311763003867136_o_480x480.jpg?v=1594621037" alt="" width="300" height="300">
<img id="myImg27" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/84172321_772995959858794_2676800983836655616_o_480x480.jpg?v=1594621056" alt="" width="300" height="300">
<img id="myImg28" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/83654132_109173690624362_9115407073113276416_o_480x480.jpg?v=1594621075" alt="" width="300" height="300">
<img id="myImg29" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/82293604_109167450624986_822550068987953152_o_480x480.jpg?v=1594621096" alt="" width="300" height="300">
<img id="myImg30" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/1_480x480.jpg?v=1594623899" alt="" width="300" height="300">
<img id="myImg31" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/2_480x480.jpg?v=1594623917" alt="" width="300" height="300">
<img id="myImg32" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/3_480x480.jpg?v=1594623944" alt="" width="300" height="300">
<img id="myImg33" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/4_480x480.jpg?v=1594623975" alt="" width="300" height="300">
<img id="myImg34" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/5_480x480.jpg?v=1594623994" alt="" width="300" height="300">
<img id="myImg35" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/6_480x480.jpg?v=1594624009" alt="" width="300" height="300">
<img id="myImg36" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/7_480x480.jpg?v=1594624033" alt="" width="300" height="300">
<img id="myImg37" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/8_480x480.jpg?v=1594624052" alt="" width="300" height="300">
<img id="myImg38" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/9_480x480.jpg?v=1594624070" alt="" width="300" height="300">
<img id="myImg39" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/10_480x480.jpg?v=1594624232" alt="" width="300" height="300">
<img id="myImg40" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/11_480x480.jpg?v=1594624254" alt="" width="300" height="300">
<img id="myImg41" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/12_480x480.jpg?v=1594624279" alt="" width="300" height="300">
<img id="myImg42" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/13_480x480.jpg?v=1594624300" alt="" wwidth="300" height="300">
<img id="myImg43" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/14_480x480.jpg?v=1594624319" alt="" width="300" height="300">
<img id="myImg44" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/15_480x480.jpg?v=1594632593" alt="" width="300" height="300">
<img id="myImg45" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/16_480x480.jpg?v=1594632610" alt="" wwidth="300" height="300">
<img id="myImg46" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/18_480x480.jpg?v=1594632635" alt="" width="300" height="300">
<img id="myImg47" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/20_480x480.jpg?v=1594632659" alt="" width="300" height="300">
<img id="myImg48" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/22_480x480.jpg?v=1594632683" alt="" width="300" height="300">
<img id="myImg49" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/23_480x480.jpg?v=1594632703" alt="" width="300" height="300">
<img id="myImg50" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/25_480x480.jpg?v=1594632732" alt="" width="300" height="300">
<img id="myImg51" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/26_480x480.jpg?v=1594632750" alt="" width="300" height="300">
<img id="myImg52" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/27_480x480.jpg?v=1594632772" alt="" width="300" height="300">
<img id="myImg53" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/28_480x480.jpg?v=1594632796" alt="" width="300" height="300">
<img id="myImg54" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/31_480x480.jpg?v=1594632826" alt="" width="300" height="300">
<img id="myImg55" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/34_480x480.jpg?v=1594632852" alt="" width="300" height="300">
<img id="myImg56" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/35_480x480.jpg?v=1594632878" alt="" width="300" height="300">
<img id="myImg57" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/36_480x480.jpg?v=1594632898" alt="" width="300" height="300">
<img id="myImg58" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/38_480x480.jpg?v=1594632927" alt="" width="300" height="300">
<img id="myImg59" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/39_480x480.jpg?v=1594632954" alt="" width="300" height="300">
<img id="myImg60" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/42_480x480.jpg?v=1594632976" alt="" width="300" height="300">
<img id="myImg61" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/44_480x480.jpg?v=1594633013" alt="" width="300" height="300">
<img id="myImg62" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/45_480x480.jpg?v=1594633031" alt="" width="300" height="300">
<img id="myImg63" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/48_480x480.jpg?v=1594633050" alt="" width="300" height="300">
<img id="myImg64" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/43_480x480.jpg?v=1594633069" alt="" width="300" height="300">
<img id="myImg65" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/49_480x480.jpg?v=1594633097" alt="" width="300" height="300">
<img id="myImg66" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/51_480x480.jpg?v=1594633119" alt="" width="300" height="300">
<img id="myImg67" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/53_480x480.jpg?v=1594633164" alt="" width="300" height="300">
<img id="myImg68" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/54_480x480.jpg?v=1594633185" alt="" width="300" height="300">
<img id="myImg69" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/55_480x480.jpg?v=1594633210" alt="" width="300" height="300">
<img id="myImg70" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/58_480x480.jpg?v=1594633535" alt="" width="300" height="300">
<img id="myImg71" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/56_480x480.jpg?v=1594633559" alt="" width="300" height="300">
<img id="myImg72" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/WhatsApp_Image_2020-10-26_at_13.22.35_600x600.jpg?v=1603779572" alt="" width="300" height="300">
<img id="myImg73" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/WhatsApp_Image_2020-10-26_at_13.22.36_600x600.jpg?v=1603779617" alt="" width="300" height="300">
<img id="myImg74" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/WhatsApp_Image_2020-10-26_at_13.22.37_600x600.jpg?v=1603779634" alt="" width="300" height="300">
<img id="myImg75" src="https://cdn.shopify.com/s/files/1/0414/1626/1789/files/WhatsApp_Image_2020-10-26_at_13.22.38_600x600.jpg?v=1603779652" alt="" width="300" height="300">

<!-- The Modal -->
<div id="myModal" class="modal">
  <span class="close">&times;</span>
  <img class="modal-content" id="img01">
  <div id="caption"></div>
</div>
<script>
// Get the modal
var modal = document.getElementById("myModal");
    var arr = ["myImg0","myImg1","myImg2", "myImg3", "myImg4", "myImg5", "myImg6", 
    "myImg7", "myImg8", "myImg9", "myImg10", "myImg11", "myImg12", "myImg13", 
    "myImg14", "myImg15", "myImg16", "myImg17", "myImg18", "myImg19", "myImg20", "myImg21", "myImg22", "myImg23", "myImg24", "myImg25", "myImg26", "myImg27", "myImg28", "myImg29", "myImg30", "myImg31", "myImg32", "myImg33", "myImg34", "myImg35", "myImg36", "myImg37", "myImg38", "myImg39", "myImg40", "myImg41", "myImg42", "myImg43", "myImg44", "myImg45", "myImg46", "myImg47", "myImg48", "myImg49", "myImg50", "myImg51", "myImg52", "myImg53", "myImg54", "myImg55", "myImg56", "myImg57", "myImg58", "myImg59", "myImg60", "myImg61", "myImg62", "myImg63", "myImg64", "myImg65", "myImg66", "myImg67", "myImg68", "myImg69", "myImg70", "myImg71", "myImg72", "myImg73", "myImg74", "myImg75"];
    for(var i=0;i< arr.length;i++)
// Get the image and insert it inside the modal - use its "alt" text as a caption
var img = document.getElementById(arr[i]);
var modalImg = document.getElementById("img01");
var captionText = document.getElementById("caption");
img.onclick = function(){
  modal.style.display = "block";
  modalImg.src = this.src;
  captionText.innerHTML = this.alt;
}

// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];

// When the user clicks on <span> (x), close the modal
span.onclick = function() { 
  modal.style.display = "none";
}
</script>

</body>
</html>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...