UNPKG

scrollto-with-animation

Version:

Animated scroll with requestAnimationFrame. For smooth animate scrollTo defining the easing, running at 60FPS and cross-browser

105 lines (104 loc) 2.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = { linearTween: function linearTween(t, b, c, d) { return c * t / d + b; }, easeInQuad: function easeInQuad(t, b, c, d) { t /= d; return c * t * t + b; }, easeOutQuad: function easeOutQuad(t, b, c, d) { t /= d; return -c * t * (t - 2) + b; }, easeInOutQuad: 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; }, easeInCubic: function easeInCubic(t, b, c, d) { t /= d; return c * t * t * t + b; }, easeOutCubic: function easeOutCubic(t, b, c, d) { t /= d; t--; return c * (t * t * t + 1) + b; }, easeInOutCubic: function easeInOutCubic(t, b, c, d) { t /= d / 2; if (t < 1) return c / 2 * t * t * t + b; t -= 2; return c / 2 * (t * t * t + 2) + b; }, easeInQuart: function easeInQuart(t, b, c, d) { t /= d; return c * t * t * t * t + b; }, easeOutQuart: function easeOutQuart(t, b, c, d) { t /= d; t--; return -c * (t * t * t * t - 1) + b; }, easeInOutQuart: function easeInOutQuart(t, b, c, d) { t /= d / 2; if (t < 1) return c / 2 * t * t * t * t + b; t -= 2; return -c / 2 * (t * t * t * t - 2) + b; }, easeInQuint: function easeInQuint(t, b, c, d) { t /= d; return c * t * t * t * t * t + b; }, easeOutQuint: function easeOutQuint(t, b, c, d) { t /= d; t--; return c * (t * t * t * t * t + 1) + b; }, easeInOutQuint: function easeInOutQuint(t, b, c, d) { t /= d / 2; if (t < 1) return c / 2 * t * t * t * t * t + b; t -= 2; return c / 2 * (t * t * t * t * t + 2) + b; }, easeInSine: function easeInSine(t, b, c, d) { return -c * Math.cos(t / d * (Math.PI / 2)) + c + b; }, easeOutSine: function easeOutSine(t, b, c, d) { return c * Math.sin(t / d * (Math.PI / 2)) + b; }, easeInOutSine: function easeInOutSine(t, b, c, d) { return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b; }, easeInExpo: function easeInExpo(t, b, c, d) { return c * Math.pow(2, 10 * (t / d - 1)) + b; }, easeOutExpo: function easeOutExpo(t, b, c, d) { return c * (-Math.pow(2, -10 * t / d) + 1) + b; }, easeInOutExpo: function easeInOutExpo(t, b, c, d) { t /= d / 2; if (t < 1) return c / 2 * Math.pow(2, 10 * (t - 1)) + b; t--; return c / 2 * (-Math.pow(2, -10 * t) + 2) + b; }, easeInCirc: function easeInCirc(t, b, c, d) { t /= d; return -c * (Math.sqrt(1 - t * t) - 1) + b; }, easeOutCirc: function easeOutCirc(t, b, c, d) { t /= d; t--; return c * Math.sqrt(1 - t * t) + b; }, easeInOutCirc: function easeInOutCirc(t, b, c, d) { t /= d / 2; if (t < 1) return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b; t -= 2; return c / 2 * (Math.sqrt(1 - t * t) + 1) + b; } };