code: function(el, duration, callback){
      duration = duration || 500;
      var start = window.pageYOffset;
  
      if (typeof el === 'number') {
        var end = parseInt(el);
      } else {
        var end = getTop(el);
      }
  
      var clock = Date.now();
      var requestAnimationFrame = window.requestAnimationFrame ||
          window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame ||
          function(fn){window.setTimeout(fn, 15);};
  
      var step = function(){
          var elapsed = Date.now() - clock;
          window.scroll(0, position(start, end, elapsed, duration));
          if (elapsed > duration) {
              if (typeof callback === 'function') {
                  callback(el);
              }
          } else {
              requestAnimationFrame(step);
          }
      }
      step();
  }
docs: we use requestAnimationFrame to be called by the browser before every repaint if the first argument is an element then scroll to the top of this element if the first argument is numeric then scroll to this location if the callback exist, it is called when the scrolling is finished