title: Hiding div when the user scrolls the div not working in JavaScript
body: <p>I have a section in my website which is built using HTML and CSS, the section is contains a scrollbar with it for users to scroll down, the complete code is below:</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>var prevScrollpos = window.pageYOffset;
  window.onscroll = function() {
    var currentScrollPos = window.pageYOffset;
    if (prevScrollpos &gt; currentScrollPos) {
      document.getElementById("zaif").style.top = "0";
    } else {
      document.getElementById("zaif").style.top = "-50px";
    }
    prevScrollpos = currentScrollPos;
  }</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.wrapsaipy {
    width: 95%;
    margin: 5px auto;
    max-width: 900px;
    font-weight: 100;
    font-family: 'Roboto', sans-serif;
  }
  
  .wrapsaipy h1 {
    font-weight: 100;
  }
  
  .termssaipy {
    color: #fff;
    height: 480px;
    cursor: move;
    padding: 10px;
    background: #43cea2;
    background: -webkit-linear-gradient(to right, #f2136e, #0cc3eb);
    background: -webkit-gradient(linear, left top, right top, from(#f2136e), to(#0cc3eb));
    background: -webkit-linear-gradient(left, #f2136e, #0cc3eb);
    background: -o-linear-gradient(left, #f2136e, #0cc3eb);
    background: linear-gradient(to right, #f2136e, #0cc3eb);
    overflow-y: scroll;
    border-radius: 3px;
    -webkit-box-shadow: 0 0 10px rgba(0, 0, 0, 0.9);
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.9);
  }
  
  .termssaipy p {
    line-height: 25px;
  }
  
  .choicessaipy {
    margin-top: 40px;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="kuttan" id="zaif"&gt;
    &lt;div class="containerkuttan"&gt;
      &lt;div class="chevron"&gt;&lt;/div&gt;
      &lt;div class="chevron"&gt;&lt;/div&gt;
      &lt;div class="chevron"&gt;&lt;/div&gt;
      &lt;span class="textkuttan"&gt;&lt;b&gt;Scroll down&lt;/b&gt;&lt;/span&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="wrapsaipy"&gt;
    &lt;h1&gt;&lt;b&gt;TERMS AND CONDITIONS&lt;/b&gt;&lt;/h1&gt;
    &lt;div class="termssaipy"&gt;
      &lt;p&gt;The terms "We" / "Us" / "Our"/”Company” individually and collectively refer to FireZeal Internet Solutions Private Limited and the terms "Visitor” ”User” refer to the users.&lt;/p&gt;
      &lt;p&gt;This page states the Terms and Conditions under which you (Visitor) may visit this website (“Website”). Please read this page carefully. If you do not accept the Terms and Conditions stated here, we would request you to exit this site. The business,
        any of its business divisions and / or its subsidiaries, associate companies or subsidiaries to subsidiaries or such other investment companies (in India or abroad) reserve their respective rights to revise these Terms and Conditions at any time
        by updating this posting. You should visit this page periodically to re-appraise yourself of the Terms and Conditions, because they are binding on all users of this Website.&lt;/p&gt;
      &lt;h3&gt;&lt;b&gt;USE OF CONTENT&lt;/b&gt;&lt;/h3&gt;
      &lt;p&gt;All logos, brands, marks headings, labels, names, signatures, numerals, shapes or any combinations thereof, appearing in this site, except as otherwise noted, are properties either owned, or used under licence, by the business and / or its associate
        entities who feature on this Website. The use of these properties or any other content on this site, except as provided in these terms and conditions or in the site content, is strictly prohibited.&lt;/p&gt;
      &lt;p&gt;You may not sell or modify the content of this Website or reproduce, display, publicly perform, distribute, or otherwise use the materials in any way for any public or commercial purpose without the respective organisation’s or entity’s written permission.&lt;/p&gt;
      &lt;h3&gt;&lt;b&gt;ACCEPTABLE WEBSITE USE&lt;/b&gt;&lt;/h3&gt;
      &lt;h5&gt;&lt;b&gt;(A) Security Rules&lt;/b&gt;&lt;/h5&gt;
      &lt;p&gt;Visitors are prohibited from violating or attempting to violate the security of the Web site, including, without limitation, (1) accessing data not intended for such user or logging into a server or account which the user is not authorised to access,
        (2) attempting to probe, scan or test the vulnerability of a system or network or to breach security or authentication measures without proper authorisation, (3) attempting to interfere with service to any user, host or network, including, without
        limitation, via means of submitting a virus or "Trojan horse" to the Website, overloading, "flooding", "mail bombing" or "crashing", or (4) sending unsolicited electronic mail, including promotions and/or advertising of products or services. Violations
        of system or network security may result in civil or criminal liability. The business and / or its associate entities will have the right to investigate occurrences that they suspect as involving such violations and will have the right to involve,
        and cooperate with, law enforcement authorities in prosecuting users who are involved in such violations.
      &lt;/p&gt;
      &lt;h5&gt;&lt;b&gt;(B) General Rules&lt;/b&gt;&lt;/h5&gt;
      &lt;p&gt;Visitors may not use the Web Site in order to transmit, distribute, store or destroy material (a) that could constitute or encourage conduct that would be considered a criminal offence or violate any applicable law or regulation, (b) in a manner that
        will infringe the copyright, trademark, trade secret or other intellectual property rights of others or violate the privacy or publicity of other personal rights of others, or (c) that is libellous, defamatory, pornographic, profane, obscene, threatening,
        abusive or hateful.&lt;/p&gt;
      &lt;h3&gt;&lt;b&gt;INDEMNITY&lt;/b&gt;&lt;/h3&gt;
      &lt;p&gt;The User unilaterally agree to indemnify and hold harmless, without objection, the Company, its officers, directors, employees and agents from and against any claims, actions and/or demands and/or liabilities and/or losses and/or damages whatsoever
        arising from or resulting from their use of or their breach of the terms .&lt;/p&gt;
      &lt;h3&gt;&lt;b&gt;LIABILITY&lt;/b&gt;&lt;/h3&gt;
      &lt;p&gt;User agrees that neither company nor its group companies, directors, officers or employee shall be liable for any direct or/and indirect or/and incidental or/and special or/and consequential or/and exemplary damages, resulting from the use or/and
        the inability to use the service or/and for cost of procurement of substitute goods or/and services or resulting from any goods or/and data or/and information or/and services purchased or/and obtained or/and messages received or/and transactions
        entered into through or/and from the service or/and resulting from unauthorized access to or/and alteration of user's transmissions or/and data or/and arising from any other matter relating to the service, including but not limited to, damages for
        loss of profits or/and use or/and data or other intangible, even if companyhas been advised of the possibility of such damages.&lt;/p&gt;
      &lt;p&gt;User further agrees that company shall not be liable for any damages arising from interruption, suspension or termination of service, including but not limited to direct or/and indirect or/and incidental or/and special consequential or/and exemplary
        damages, whether such interruption or/and suspension or/and termination was justified or not, negligent or intentional, inadvertent or advertent. User agrees that companyshall not be responsible or liable to user, or anyone, for the statements or
        conduct of any third party of the service. In sum, in no event shall Company's total liability to the User for all damages or/and losses or/and causes of action exceed the amount paid by the User to company, if any, that is related to the cause
        of action.&lt;/p&gt;
      &lt;h3&gt;&lt;b&gt;DISCLAIMER OF CONSEQUENTIAL DAMAGES&lt;/b&gt;&lt;/h3&gt;
      &lt;p&gt;In no event shall Company or any parties, organizations or entities associated with the corporate brand name us or otherwise, mentioned at this Website be liable for any damages whatsoever (including, without limitations, incidental and consequential
        damages, lost profits, or damage to computer hardware or loss of data information or business interruption) resulting from the use or inability to use the Website and the Website material, whether based on warranty, contract, tort, or any other
        legal theory, and whether or not, such organization or entities were advised of the possibility of such damages.&lt;/p&gt;
  
  
    &lt;/div&gt;
  
  
  
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>As you can see I have given a div saying &quot;scroll down&quot; so users will understand there is content below. I want the div to be hidden when the user scrolls the bar, as you can see I have given JavaScript to it, but it's not working. Can anyone please tell me what could be wrong here.</p>