title: if/else statement with setTimeout causes flicker
body: <p>I'm displaying an element on scrolling down and hiding it when scrolling up again. Without using setTimeout, this works just as expected. However, using setTimeout causes the 'display' class to be added and removed in short intervals when scrolling down. How can I avoid this while keeping the delay?</p>
  
  <pre><code>onscroll = function() {
    var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
    if (scrollTop &gt; 110) {
      menuButton.classList.add('display');
    } else {
      setTimeout(function() {
        menuButton.classList.remove('display');
      }, 400);
    }
  }
  </code></pre>