examples/validation/dist/index.js
function scrollTo(target) {
    var duration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 500;
    var offset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
    var rootElement = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : window;

    return new Promise(function (onAnimationEnd) {

      var element = void 0;
      if (typeof target === 'string') {
        element = document.querySelector(target);
      } else if ((typeof target === 'undefined' ? 'undefined' : babelHelpers.typeof(target)) === 'object') {
        element = target;
      } else {
        // number
        element = null;
      }

      if (element !== null && element.offsetParent === null) {
        // element is not visible, scroll to top of parent element
        element = element.parentNode;
      }

      var start = rootElement === window ? window.pageYOffset : rootElement.scrollTop;
      var distance = 0;
      if (element !== null) {
        distance = element.getBoundingClientRect().top;
      } else {
        // number
        distance = target;
      }

      distance = distance + offset;

      if (typeof duration === 'function') {
        duration = duration(distance);
      }

      var timeStart = 0;
      var timeElapsed = 0;

      requestAnimationFrame(function (time) {
        timeStart = time;
        loop(time);
      });

      function setScrollYPosition(el, y) {
        if (el === window) {
          window.scrollTo(0, y);
        } else {
          el.scrollTop = y;
        }
      }

      function loop(time) {
        timeElapsed = time - timeStart;
        setScrollYPosition(rootElement, easeInOutQuad(timeElapsed, start, distance, duration));
        if (timeElapsed < duration) {
          requestAnimationFrame(loop);
        } else {
          end();
        }
      }

      function end() {
        setScrollYPosition(rootElement, start + distance);
        onAnimationEnd();
      }

      // Robert Penner's easeInOutQuad - http://robertpenner.com/easing/
      function easeInOutQuad(t, b, c, d) {
        t /= d / 2;
        if (t < 1) return c / 2 * t * t + b;
        t--;
        return -c / 2 * (t * (t - 2) - 1) + b;
      }
    });
  }
function scrollTo(target) {
    var duration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 500;
    var offset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
    var rootElement = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : window;

    return new Promise(function (onAnimationEnd) {

      var element = void 0;
      if (typeof target === 'string') {
        element = document.querySelector(target);
      } else if ((typeof target === 'undefined' ? 'undefined' : babelHelpers.typeof(target)) === 'object') {
        element = target;
      } else {
        // number
        element = null;
      }

      if (element !== null && element.offsetParent === null) {
        // element is not visible, scroll to top of parent element
        element = element.parentNode;
      }

      var start = rootElement === window ? window.pageYOffset : rootElement.scrollTop;
      var distance = 0;
      if (element !== null) {
        distance = element.getBoundingClientRect().top;
      } else {
        // number
        distance = target;
      }

      distance = distance + offset;

      if (typeof duration === 'function') {
        duration = duration(distance);
      }

      var timeStart = 0;
      var timeElapsed = 0;

      requestAnimationFrame(function (time) {
        timeStart = time;
        loop(time);
      });

      function setScrollYPosition(el, y) {
        if (el === window) {
          window.scrollTo(0, y);
        } else {
          el.scrollTop = y;
        }
      }

      function loop(time) {
        timeElapsed = time - timeStart;
        setScrollYPosition(rootElement, easeInOutQuad(timeElapsed, start, distance, duration));
        if (timeElapsed < duration) {
          requestAnimationFrame(loop);
        } else {
          end();
        }
      }

      function end() {
        setScrollYPosition(rootElement, start + distance);
        onAnimationEnd();
      }

      // Robert Penner's easeInOutQuad - http://robertpenner.com/easing/
      function easeInOutQuad(t, b, c, d) {
        t /= d / 2;
        if (t < 1) return c / 2 * t * t + b;
        t--;
        return -c / 2 * (t * (t - 2) - 1) + b;
      }
    });
  }
function scrollTo ( target ) { var duration = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : 500 ; var offset = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : 0 ; var rootElement = arguments . length > 3 && arguments [ 3 ] !== undefined ? arguments [ 3 ] : window ; return new Promise ( function ( onAnimationEnd ) { var element = void 0 ; if ( typeof target === 'string' ) { element = document . querySelector ( target ) ; } else if ( ( typeof target === 'undefined' ? 'undefined' : babelHelpers . typeof ( target ) ) === 'object' ) { element = target ; } else { // number element = null ; } if ( element !== null && element . offsetParent === null ) { // element is not visible, scroll to top of parent element element = element . parentNode ; } var start = rootElement === window ? window . pageYOffset : rootElement . scrollTop ; var distance = 0 ; if ( element !== null ) { distance = element . getBoundingClientRect ( ) . top ; } else { // number distance = target ; } distance = distance + offset ; if ( typeof duration === 'function' ) { duration = duration ( distance ) ; } var timeStart = 0 ; var timeElapsed = 0 ; requestAnimationFrame ( function ( time ) { timeStart = time ; loop ( time ) ; } ) ; function setScrollYPosition ( el , y ) { if ( el === window ) { window . scrollTo ( 0 , y ) ; } else { el . scrollTop = y ; } } function loop ( time ) { timeElapsed = time - timeStart ; setScrollYPosition ( rootElement , easeInOutQuad ( timeElapsed , start , distance , duration ) ) ; if ( timeElapsed < duration ) { requestAnimationFrame ( loop ) ; } else { end ( ) ; } } function end ( ) { setScrollYPosition ( rootElement , start + distance ) ; onAnimationEnd ( ) ; } // Robert Penner's easeInOutQuad - http://robertpenner.com/easing/ function easeInOutQuad ( t , b , c , d ) { t /= d / 2 ; if ( t < 1 ) return c / 2 * t * t + b ; t -- ; return - c / 2 * ( t * ( t - 2 ) - 1 ) + b ; } } ) ; }
Smooth scrolling to DOM element or to relative window position
If target is string it should be CSS selector
If target is object it should be DOM element
If target is number - it is used to relatively scroll X pixels form current position

Based on https://www.sitepoint.com/smooth-scrolling-vanilla-javascript/

@param {HTMLElement, string, number} target
@param {Number|function} duration
@param {Number} offset
@param {HTMLElement} rootElement
Smooth scrolling to DOM element or to relative window position If target is string it should be CSS selector If target is object it should be DOM element If target is number - it is used to relatively scroll X pixels form current position