Blur+Zoom Nested Modals

by 2jddfsjad

HTML

<a href="#myModal1" class="modal-button">This is the trigger <em> for the first modal</em></a><br>
<a href="#myModal3" class="modal-button">This is the trigger <em> for the second modal</em></a>
  

  <!-- The Modal -->
  <div id="myModal1" class="modal">
    <!-- Modal content -->
    <div class="modal-content">
      <div class="modal-header"><span class="close">×</span>
        <div class="headertext">Modal window 1</div>
      </div>
      <div class="modal-body">
        <img class="pic" src="https://drive.google.com/thumbnail?id=108ZLeoIfNkKODfRbLuPWpmXRl0gH9qkD">
        <div class="bodytext">
          <ul>
            <li>You are currently viewing first Modal window <span class="bold"><a href="#myModal2" class="modal-button">Click here to open second modal window</a></span></li>
          </ul>
        </div>
      </div>
    </div>
  </div>

  <!-- The Modal -->
  <div id="myModal2" class="modal">
    <!-- Modal content -->
    <div class="modal-content">
      <div class="modal-header"><span class="close">×</span>
        <div class="headertext">Modal window 2</div>
      </div>
      <div class="modal-body">
        <img class="pic" src="https://drive.google.com/thumbnail?id=108ZLeoIfNkKODfRbLuPWpmXRl0gH9qkD">
        <div class="bodytext">You are currently viewing Modal window 2</div>
      </div>
    </div>
  </div>

  <!-- The Modal -->
  <div id="myModal3" class="modal">
    <!-- Modal content -->
    <div class="modal-content">
      <div class="modal-header"><span class="close">×</span>
        <div class="headertext">Modal window 3</div>
      </div>
      <div class="modal-body">
        <img class="pic" src="https://drive.google.com/thumbnail?id=108ZLeoIfNkKODfRbLuPWpmXRl0gH9qkD">
        <div class="bodytext">You are currently viewing Modal window 3</div>
      </div>
    </div>
  </div>

CSS

.modal {
  box-sizing: border-box;
  font-family: 'Quicksand', sans-serif;
  display: none;
  /* Hidden by default */
  position: fixed;
  /* Stay in place */
  z-index: 1;
  /* Sit on top */
  padding-top: 3.125rem;
  /* 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.4);
  /* Black w/ opacity */
}


/* Modal Content */

.modal-content {
  color: white;
  position: relative;
  background-color: #171B20;
  margin: auto;
  padding: 0;
  border: 0.0625rem solid #888;
  width: 90%;
  box-shadow: 0 0.25rem 0.5rem 0 rgba(0, 0, 0, 0.2), 0 0.375rem 1.25rem 0 rgba(0, 0, 0, 0.19);
  -webkit-animation-name: animatetop;
  -webkit-animation-duration: 0.4s;
  animation-name: animatetop;
  animation-duration: 0.4s;
}


/* Add Animation */
@keyframes animatetop {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}


@keyframes animateBottom {
  from {

    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

.modal-content-active {
  -webkit-animation-name: animateBottom;
  -webkit-animation-duration: 0.4s;
  animation-name: animateBottom;
  animation-duration: 0.4s;
}


/* The Close Button */

.close {
  color: #F0B823;
  float: right;
  font-size: 2.6rem;
  font-weight: bold;
  position: absolute;
  right: 0.25rem;
  top: -0.25rem;
}

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

.modal-header {
  padding: 0.125rem 1rem;
  background-color: #171B20;
  color: #F0B823;
}

.modal-button {
    border: none;
  padding: 0.248em 0.496em;
  text-align: left;
  text-decoration: none;
  margin: 0.124em 0.062em;
  -webkit-transition-duration: 0;
  transition-duration: 0;
  cursor: pointer;
  width: auto;
}

.pic {
  margin: auto;
  display: block;
  height: auto;
  width: 50vh;
}

.headertext {
  font-family: 'Quicksand', sans-serif;
 ...

JavaScript

$(function () {
  const openModals = [];
  $('.modal-button').click(e => {
    e.preventDefault();
    $(e.target).closest('.modal').add('body').addClass('open');
    openModals.push($($(e.target).attr('href')).show());
  });
  $(window).add('.close').click(e => {
    e.stopPropagation();
    if ($(e.target).is('.modal, .close')) {
      const closing = openModals.pop().addClass('modal-content-active');
      setTimeout(() => {closing.hide().removeClass('modal-content-active')}, 0);
      if (openModals.length > 0) {
        openModals[openModals.length - 1].removeClass('open');
      } else $('body').removeClass('open');
    }
  });
});