·   ·  6 posts
  •  ·  36 friends

Modal to post's photos

  1. Go Studio
  2. Pages -> Posts
  3. Select "View Post" page
  4. Add new "raw block"
  5. Add the code below and name it "JS Modal"
  6. Set Block Layout to "Content"
  7. Save
<style>
.ImgThumbnail {
border-radius: 5px;
cursor: pointer;
transition: 0.3s;
}
.ImgThumbnail:nth-of-type(1) {
margin-left: 20%;
}
.modal {
display: none;
position: fixed;
z-index: 1;
padding-top: 100px;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgb(0, 0, 0);
background-color: rgba(0, 0, 0, 0.9);
}
.modalImage {
margin: auto;
display: block;
width: 50%;
height: 60%;
max-width: 700px;
}
 {
margin: auto;
display: block;
width: 80%;
max-width: 700px;
text-align: center;
color: ;
padding: 10px 0;
height: 150px;
}
.close {
position: absolute;
top: 15px;
right: 35px;
color: ;
font-size: 40px;
font-weight: bold;
transition: 0.3s;
}
.close:hover,
.close:focus {
color: rgb(255, 0, 0);
cursor: pointer;
}
@media only screen and (max-width: 700px) {
.modalImage {
width: 100%;
}

}

.fr-fic.fr-dib{cursor:pointer;}
</style>
<!-- The Modal -->
<div class="modal">
<span class="close">×</span>
<img class="modalImage" id="img01" />
</div>
<script>
$(document).ready(function () {
var modalEle = document.querySelector(".modal");
var modalImage = document.querySelector(".modalImage");
Array.from(document.querySelectorAll(".fr-fic")).forEach(item => {
item.addEventListener("click", event => {
modalEle.style.display = "block";
modalImage.src = event.target.src;
});
});
document.querySelector(".close").addEventListener("click", () => {
modalEle.style.display = "none";
});
});
</script>

That's it

  • 3559
  • More
Comments (2)
    Login or Join to comment.