function scrollTo( to, opts ) {
  opts = opts && typeof opts === 'object' ? opts : {};
  var startPosition = window.pageYOffset;
  var distance = to - startPosition;
  var duration = opts.duration || _calculateDuration( distance );
  var startTime;

  function scroll( timestamp ) {
    startTime = startTime || timestamp;
    var elapsed = timestamp - startTime;
    var next = _easeInOutQuad( elapsed, startPosition, distance, duration );
    window.scroll( 0, next );
    if ( elapsed < duration ) {
      _requestAnimationFrame( scroll );
    } else if ( typeof opts.callback === 'function' ) {
      opts.callback();
    }
  }

  if ( Math.abs( distance ) > 3 ) {
    _requestAnimationFrame( scroll );
  }
}
/**
 * Animated scroll to a location in page.
 * @param {Number} to The y-coordinate to scroll to
 * @param {Object} opts Optional parameters, including:
 * 		duration: Duration of the scroll animation
 * 		callback: To be called when scroll is complete
 *
 */
Animated scroll to a location in page.
@param {Number} to The y-coordinate to scroll to
@param {Object} opts Optional parameters, including:
duration: Duration of the scroll animation
callback: To be called when scroll is complete
Animated scroll to a location in page . @param { Number } to The y - coordinate to scroll to @param { Object } opts Optional parameters including : duration : Duration of the scroll animation callback : To be called when scroll is complete
function scrollTo( to, opts ) {
  opts = opts && typeof opts === 'object' ? opts : {};
  var startPosition = window.pageYOffset;
  var distance = to - startPosition;
  var duration = opts.duration || _calculateDuration( distance );
  var startTime;
  function scroll( timestamp ) {
    startTime = startTime || timestamp;
    var elapsed = timestamp - startTime;
    var next = _easeInOutQuad( elapsed, startPosition, distance, duration );
    window.scroll( 0, next );
    if ( elapsed < duration ) {
      _requestAnimationFrame( scroll );
    } else if ( typeof opts.callback === 'function' ) {
      opts.callback();
    }
  }
  if ( Math.abs( distance ) > 3 ) {
    _requestAnimationFrame( scroll );
  }
}
function scrollTo ( to , opts ) { opts = opts && typeof opts === 'object' ? opts : { } ; var startPosition = window . pageYOffset ; var distance = to - startPosition ; var duration = opts . duration || _calculateDuration ( distance ) ; var startTime ; function scroll ( timestamp ) { startTime = startTime || timestamp ; var elapsed = timestamp - startTime ; var next = _easeInOutQuad ( elapsed , startPosition , distance , duration ) ; window . scroll ( 0 , next ) ; if ( elapsed < duration ) { _requestAnimationFrame ( scroll ) ; } else if ( typeof opts . callback === 'function' ) { opts . callback ( ) ; } } if ( Math . abs ( distance ) > 3 ) { _requestAnimationFrame ( scroll ) ; } }
Animated scroll to a location in page.
Animated scroll to a location in page .