app/src/vendor/scroll.js
/**
     * Scrolls the element until it's scroll properties match the coordinates provided.
     * @param {Number} x - The pixel along the horizontal axis of the element that you want displayed in the upper left.
     * @param {Number} y - The pixel along the vertical axis of the element that you want displayed in the upper left.
     * @param {Object} [options] - Scroll options
     * @param {Number} [options.duration]- The amount of time for the animation
     * @param {string} [options.easing] - The easing function to use
     * @return {Promise}
     */
Scrolls the element until it's scroll properties match the coordinates provided.
@param {Number} x - The pixel along the horizontal axis of the element that you want displayed in the upper left.
@param {Number} y - The pixel along the vertical axis of the element that you want displayed in the upper left.
@param {Object} [options] - Scroll options
@param {Number} [options.duration]- The amount of time for the animation
@param {string} [options.easing] - The easing function to use
@return {Promise}
Scrolls the element until it ' s scroll properties match the coordinates provided . @param { Number } x - The pixel along the horizontal axis of the element that you want displayed in the upper left . @param { Number } y - The pixel along the vertical axis of the element that you want displayed in the upper left . @param { Object } [ options ] - Scroll options @param { Number } [ options . duration ] - The amount of time for the animation @param { string } [ options . easing ] - The easing function to use @return { Promise }
to (x, y, options) {
        var elem = this.el,
            fromY = elem.scrollTop,
            fromX = elem.scrollLeft;
        options = options || {};
        options.duration = options.duration || 400;
        let moveElement = (prop, value) => {
            var el = this.el;
            el[prop] = value;
            if (el === this.document.body) {
                this.document.documentElement[prop] = value;
            }
        };
        let scroll = (el, from, to, prop, startTime, duration, easeFunc, callback) => {
            window.requestAnimationFrame(() => {
                var currentTime = Date.now(),
                    time = Math.min(1, ((currentTime - startTime) / duration));
                if (from === to) {
                    return callback ? callback() : null;
                }
                moveElement(prop, (easeFunc(time) * (to - from)) + from);
                if (time < 1) {
                    scroll(el, el[prop], to, prop, startTime, duration, easeFunc, callback);
                } else if (callback) {
                    callback();
                }
            });
        };
        return new Promise((resolve) => {
            scroll(elem, fromY, y, 'scrollTop', Date.now(), options.duration, getEasing(options.easing), resolve);
        });
    }
to ( x , y , options ) { var elem = this . el , fromY = elem . scrollTop , fromX = elem . scrollLeft ; options = options || { } ; options . duration = options . duration || 400 ; let moveElement = ( prop , value ) => { var el = this . el ; el [ prop ] = value ; if ( el === this . document . body ) { this . document . documentElement [ prop ] = value ; } } ; let scroll = ( el , from , to , prop , startTime , duration , easeFunc , callback ) => { window . requestAnimationFrame ( ( ) => { var currentTime = Date . now ( ) , time = Math . min ( 1 , ( ( currentTime - startTime ) / duration ) ) ; if ( from === to ) { return callback ? callback ( ) : null ; } moveElement ( prop , ( easeFunc ( time ) * ( to - from ) ) + from ) ; if ( time < 1 ) { scroll ( el , el [ prop ] , to , prop , startTime , duration , easeFunc , callback ) ; } else if ( callback ) { callback ( ) ; } } ) ; } ; return new Promise ( ( resolve ) => { scroll ( elem , fromY , y , 'scrollTop' , Date . now ( ) , options . duration , getEasing ( options . easing ) , resolve ) ; } ) ; }
Scrolls the element until it's scroll properties match the coordinates provided.
Scrolls the element until it ' s scroll properties match the coordinates provided .
// defaults /**
         * Sets element's property to a value.
         * @param {string} prop - The property to set
         * @param {Number} value - The number value
         */ // scroll the html element also for cross-browser compatibility // (ie. silly browsers like IE who need the html element to scroll too) /**
         * Does a bit of calculating and scrolls an element.
         * @param {HTMLElement} el - The element to be scrolled
         * @param {Number} from - The number of where to scroll from
         * @param {Number} to - The number of where to scroll to
         * @param {string} prop - The property to animate
         * @param {Number} startTime - The timestamp of when the animation should start
         * @param {Number} duration - The amount of time for the animation
         * @param {Function} easeFunc - The easing function to use
         * @param [callback]
         */ /* prevent scrolling, if already there, or at end */