function watchScroll(viewAreaElement, callback) {
  var debounceScroll = function debounceScroll(evt) {
    if (rAF) {
      return;
    }
    // schedule an invocation of scroll for next animation frame.
    rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
      rAF = null;

      var currentY = viewAreaElement.scrollTop;
      var lastY = state.lastY;
      if (currentY !== lastY) {
        state.down = currentY > lastY;
      }
      state.lastY = currentY;
      callback(state);
    });
  };

  var state = {
    down: true,
    lastY: viewAreaElement.scrollTop,
    _eventHandler: debounceScroll
  };

  var rAF = null;
  viewAreaElement.addEventListener('scroll', debounceScroll, true);
  return state;
}
/**
 * Helper function to start monitoring the scroll event and converting them into
 * PDF.js friendly one: with scroll debounce and scroll direction.
 */
Helper function to start monitoring the scroll event and converting them into
PDF.js friendly one: with scroll debounce and scroll direction.
Helper function to start monitoring the scroll event and converting them into PDF . js friendly one : with scroll debounce and scroll direction .
function watchScroll(viewAreaElement, callback) {
  var debounceScroll = function debounceScroll(evt) {
    if (rAF) {
      return;
    }
    rAF = window.requestAnimationFrame(function viewAreaElementScrolled() {
      rAF = null;
      var currentY = viewAreaElement.scrollTop;
      var lastY = state.lastY;
      if (currentY !== lastY) {
        state.down = currentY > lastY;
      }
      state.lastY = currentY;
      callback(state);
    });
  };
  var state = {
    down: true,
    lastY: viewAreaElement.scrollTop,
    _eventHandler: debounceScroll
  };
  var rAF = null;
  viewAreaElement.addEventListener('scroll', debounceScroll, true);
  return state;
}
function watchScroll ( viewAreaElement , callback ) { var debounceScroll = function debounceScroll ( evt ) { if ( rAF ) { return ; } rAF = window . requestAnimationFrame ( function viewAreaElementScrolled ( ) { rAF = null ; var currentY = viewAreaElement . scrollTop ; var lastY = state . lastY ; if ( currentY !== lastY ) { state . down = currentY > lastY ; } state . lastY = currentY ; callback ( state ) ; } ) ; } ; var state = { down : true , lastY : viewAreaElement . scrollTop , _eventHandler : debounceScroll } ; var rAF = null ; viewAreaElement . addEventListener ( 'scroll' , debounceScroll , true ) ; return state ; }
Helper function to start monitoring the scroll event and converting them into
 PDF.js friendly one: with scroll debounce and scroll direction.
Helper function to start monitoring the scroll event and converting them into PDF . js friendly one : with scroll debounce and scroll direction .
// schedule an invocation of scroll for next animation frame.