code: function onScroll(cb) {
    var isTicking = false;
    var scrollY = 0;
    var body = document.body;
    var html = document.documentElement;
    var scrollHeight = Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight);
    function scroll() {
      scrollY = window.scrollY;
      if (cb) cb(scrollY, scrollHeight);
      requestTick();
    }
    function requestTick() {
      if (!isTicking) requestAnimationFrame(updateScroll);
      isTicking = true;
    }
    function updateScroll() {
      isTicking = false;
      var currentScrollY = scrollY;
    }
    scroll();
    window.onscroll = scroll;
  }
docs: Better scroll events