I've created two modal's and I'm unsure how to make them both close with the same button. the first modal is closing fine, but, the second one won't close at all.
I'm also looking to give them an animation to slide in and out. However, I can't work out how to add it to the code that I've already created. Can anyone suggest how I could do this?
document.getElementById('project-1').addEventListener("click", function() {
document.querySelector('.side-modal').style.display = "flex";
});
document.getElementById('project-2').addEventListener("click", function() {
document.querySelector('.side-modal.second').style.display = "flex";
});
document.querySelector('.close-side-modal').addEventListener("click", function() {
document.querySelector('.side-modal, .side-modal.second').style.display = "none";
});
.side-modal {
width: 35%;
position: fixed;
height: 100%;
background-color: #fff;
top: 0;
right: 0;
bottom: 0;
align-items: center;
justify-content: center;
-moz-box-shadow: 0px 0px 20px 0px rgba(0, 0, 0, 0.1);
-webkit-box-shadow: 0px 0px 20px 0px rgba(0, 0, 0, 0.1);
box-shadow: 0px 0px 20px 0px rgba(0, 0, 0, 0.1);
display: none;
}
.side-modal .modal-content {
height: 100%;
width: unset;
}
.side-modal .close {
color: #000 !important;
}
.button {
font-size: 15px;
color: #000;
}
.close {
font-size: 40px;
color: #fff;
transform: rotate(45deg);
position: absolute;
right: 20px;
top: 0px;
font-weight: 200;
cursor: pointer;
}
<a href="#" id="project-1" class="project-1 button">project 1</a>
<a href="#" id="project-2" class="project-2 button">project 2</a>
<div class="side-modal">
<div class="modal-content">
<h2>first modal</h2>
<div class="close close-side-modal">+</div>
</div>
</div>
<div class="side-modal second">
<div class="modal-content">
<h2>second modal</h2>
<div class="close close-side-modal">+</div>
</div>
</div>