title: Closing Animation on Modal Popup
body: <p>I am working to create a modal popup. I need to add a slide up animation when the popup is closed. There is an animation when the popup opens but noting when the popup closes.</p>
  
  <p>Here is the codepen on which I am working: 
  <a href="https://codepen.io/ankitkaulmachama/pen/bGGBMeb" rel="nofollow noreferrer">https://codepen.io/ankitkaulmachama/pen/bGGBMeb</a></p>
  
  <p>Following is my code: </p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;h2&gt;Animated Modal with Header and Footer&lt;/h2&gt;
  
  &lt;!-- Trigger/Open The Modal --&gt;
  &lt;button id="myBtn"&gt;Open Modal&lt;/button&gt;
  
  &lt;!-- The Modal --&gt;
  &lt;div id="myModal" class="modal"&gt;
  
    &lt;!-- Modal content --&gt;
    &lt;div class="modal-content"&gt;
     &lt;span class="close"&gt;&amp;times;&lt;/span&gt;
      &lt;div class="modal-body"&gt;
        &lt;p&gt;Some text in the Modal Body&lt;/p&gt;
        &lt;p&gt;Some other text...&lt;/p&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  
  &lt;/div&gt;
  
  </code></pre>
  
  <p>CSS :</p>
  
  <pre><code>/* The Modal (background) */
  .modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 9999999; /* Sit on top */
    padding-top: 10px; /* Location of the box */
    left: 10px;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Enable scroll if needed */
  }
  
  /* Modal Content */
  .modal-content {
    position: relative;
    background-color: #fefefe;
    padding: 0;
    border: 1px solid #888;
    width: 350px;
    box-shadow: 0 2px 4px 0 rgba(0,0,0,0.2),0 3px 10px 0 rgba(0,0,0,0.19);
    -webkit-animation-name: animatetop;
    -webkit-animation-duration: 0.9s;
    animation-name: animatetop;
    animation-duration: 0.9s;
    border-radius:5px;
  }
  
  /* Add Animation */
  @-webkit-keyframes animatetop {
    from {top:-300px; opacity:0} 
    to {top:0; opacity:1}
  }
  
  @keyframes animatetop {
    from {top:-300px; opacity:0}
    to {top:0; opacity:1}
  }
  
  /* The Close Button */
  .close {
    color: #cdcdcd;
    float: right;
    font-weight: bold;
    padding-right:5px;
    padding-top:5px;
  }
  
  .close:hover,
  .close:focus {
    color: #000;
    text-decoration: none;
    cursor: pointer;
  }
  
  
  .modal-body {padding: 2px 16px;}
  
  .modal-footer {
    padding: 2px 16px;
    background-color: #5cb85c;
    color: white;
  }
  </code></pre>
  
  <p>JAVASCRIPT:</p>
  
  <pre><code>window.onload = function() {
  
  var modal = document.getElementById("myModal");
  var btn = document.getElementById("myBtn");
  var span = document.getElementsByClassName("close")[0];
  
  // Get the &lt;span&gt; element that closes the modal
  var span = document.getElementsByClassName("close")[0];
  
  // When the user clicks the button, open the modal 
  btn.onclick = function() {
    modal.style.display = "block";
  }
  
  // When the user clicks on &lt;span&gt; (x), close the modal
  span.onclick = function() {
    modal.style.display = "none";
  }
  
  function showPopup()
  {
          modal.style.display = "block";
  }
  
  function hidePopup()
  {
          modal.style.display = "none";
  }
  }
  </code></pre>
  
  <p>Any help to accomplish this would be grateful.</p>