title: Detecting click on window scrollbar
body: <p>I'm trying to pause the main window scroll when scrolling a table, which I've done but are having trouble enabling the main window scroll again after.</p>
  
  <p>This function will pause the main window scroll when scrolling over table.</p>
  
  <pre><code>function preventWindowScroll() {
  
    scrollTable = document.querySelector(".members-data");
  
    if (scrollTable.contains(event.target)) {
  
  var oldScrollPos = document.body.scrollTop;
  
  window.onscroll = function () { window.scrollTo(0, oldScrollPos); };
  
    } else {
     // disable scrollTo in order to reenable main window pause
      window.onscroll = function () {};
    }
  }
  </code></pre>
  
  <p>The problem is that if I try to scroll down by clicking and dragging the main window scrollbar it's still jammed by scrollTo.
  I've tried doing an onclick event, but it doesn't work when clicking scrollbar.</p>
  
  <pre><code>  document.body.onclick = function(e) {
  
    scrollTable = document.querySelector(".members-data");
  
    if (!scrollTable.contains(e.target)) {
     window.onscroll = function () {};
    }
  };
  </code></pre>
  
  <p>I've also tried removing the event listener, but can't figure out where to put it.</p>
  
  <pre><code> document.body.removeEventListener('mousewheel', preventWindowScroll);
   document.body.removeEventListener('DOMMouseScroll', preventWindowScroll);
  </code></pre>
  
  <p>If I could just detect when a user clicks on the main window scroll eit would work as intended.</p>
  
  <p>note: I have achieved pausing the main window scroll other ways, but they all have slight drawbacks.</p>
  
  <p>Thanks</p>