title: Slide up and slide down on mouse scroll
body: <p>I created two divs in a page. The first div, <code>.first-box</code>, slides up when I scroll down. Therefore page <code>.main-container</code> scrolls as I scroll down. When I scroll up the page scrolls up well. However when <code>.main-container</code> reaches the top and I scroll up I wish <code>.first-box</code> to slide down, but this does not work. </p>
  
  <p>I don't have deep knowledge of jQuery, but I used something as below. Please help me to improve it so that the first div slides down when the position of <code>.main-container</code> will at the top of the window.</p>
  
  <p>I expect the first div slides down after main container scroll up top position.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$(window).bind('mousewheel DOMMouseScroll', function(event) {
    if (event.originalEvent.wheelDelta &gt; 0 || event.originalEvent.detail &lt; 0) {
      // scroll up
      $(window).scroll(function() {
        if ($(this).scrollTop()) {
          $('.first-box').slideDown();
        }
      });
    } else {
      // scroll down
      $('.first-box').slideUp();
    }
  });</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>body {
    margin: 0;
    padding: 0;
    overflow: hidden;
  }
  
  p {
    padding: 10px 50px;
    font-size: 18px;
    font-family: Arial;
  }
  
  .first-box {
    position: fixed;
    display: block;
    width: 100%;
    height: 100%;
    background: #000;
    color: #fff;
    z-index: 9;
  }
  
  .main-container {
    position: absolute;
    top: 20px;
    left: 20px;
    bottom: 20px;
    right: 20px;
    padding: 30px;
    overflow-y: scroll;
    overflow-x: hidden;
  }
  
  
  /* Let's get this party started */
  
   ::-webkit-scrollbar {
    width: 12px;
  }
  
  
  /* Track */
  
   ::-webkit-scrollbar-track {
    -webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
    -webkit-border-radius: 10px;
    border-radius: 10px;
  }
  
  
  /* Handle */
  
   ::-webkit-scrollbar-thumb {
    -webkit-border-radius: 10px;
    border-radius: 10px;
    background: rgba(255, 0, 0, 0.8);
    -webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.5);
  }
  
   ::-webkit-scrollbar-thumb:window-inactive {
    background: rgba(255, 0, 0, 0.4);
  }
  
  .second-box {
    width: 100%;
    height: 100%;
    background: red;
    color: #fff;
  }
  
  .third-box {
    width: 100%;
    height: 100%;
    background: yellow;
    color: #fff;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;div class="first-box"&gt;first box&lt;/div&gt;
  &lt;div class="main-container"&gt;
    &lt;div class="second-box"&gt;
      &lt;p&gt;some text&lt;/p&gt;
      &lt;p&gt;some text&lt;/p&gt;
      &lt;p&gt;some text&lt;/p&gt;
      &lt;p&gt;some text&lt;/p&gt;
    &lt;/div&gt;
    &lt;div class="third-box"&gt;
      &lt;p&gt;some text&lt;/p&gt;
      &lt;p&gt;some text&lt;/p&gt;
      &lt;p&gt;some text&lt;/p&gt;
      &lt;p&gt;some text&lt;/p&gt;
    &lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>