// this.x, this.startX, duration, this.maxScrollX|Y, this.options.bounce ? this.wrapperWidth|Height : 0, this.options export function momentum(current, start, time, lowerMargin, wrapperSize, options) { let distance = current - start; let speed = Math.abs(distance) / time; // deceleration = 0.001, itemHeight, swipeBounceTime = 1200, bounceTime = 700 let {deceleration, itemHeight, swipeBounceTime, bounceTime} = options; // swipeTime = 2500 let duration = options.swipeTime; let rate = options.wheel ? 4 : 15; // // (distance < 0 ? -1 : 1) 判断往上滚动,还是往下滚动 let destination = current + speed / deceleration * (distance < 0 ? -1 : 1); if (options.wheel && itemHeight) { destination = Math.round(destination / itemHeight) * itemHeight; } // destination < lowerMargin判断往(下|右)方向, destination > 0 相反 if (destination < lowerMargin) { // destination = wrapperSize ? lowerMargin - (wrapperSize / rate * speed) : lowerMargin; duration = swipeBounceTime - bounceTime; } else if (destination > 0) { // destination = wrapperSize ? wrapperSize / rate * speed : 0; duration = swipeBounceTime - bounceTime; } return { destination: Math.round(destination), duration }; };
相关分类