title: Detecting scroll direction
body: <p>So I am trying to use the JavaScript <code>on scroll</code> to call a function. But I wanted to know if I could detect the direction of the the scroll without using jQuery. If not then are there any workarounds?</p>
  
  <p>I was thinking of just putting a 'to top' button but would like to avoid that if I could.</p>
  
  <p>I have now just tried using this code but it didn't work:</p>
  
  <pre><code>if document.body.scrollTop &lt;= 0 {
      alert ("scrolling down")
  } else {
      alert ("scrolling up")
  }
  </code></pre>