How to raise up the refresh rate and lower CPU usage

July 14, 2017

(function() {
  var lastScrollY = 0;
  var ticking = false;

  var update = function() {
    // do your stuff
    ticking = false;
  };

  var requestTick = function() {
    if (!ticking) {
      window.requestAnimationFrame(update);
      ticking = true;
    }
  };

  var onScroll = function() {
    lastScrollY = window.scrollY;
    requestTick();
  };

  $(window).on('scroll', onScroll);
})();

Tagged withDOM, javascript, JQuery

Questions, Comments, Suggestions? Open an Issue