scrollTo.js 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. import { w as r } from "./index2.js";
  2. function p(n, i, c, l) {
  3. const e = c - i;
  4. return n /= l / 2, n < 1 ? e / 2 * n * n * n + i : e / 2 * ((n -= 2) * n * n + 2) + i;
  5. }
  6. function u(n) {
  7. return n != null && n === n.window;
  8. }
  9. function a(n, i) {
  10. var c, l;
  11. if (typeof window == "undefined")
  12. return 0;
  13. const e = "scrollTop";
  14. let o = 0;
  15. return u(n) ? o = n.scrollY : n instanceof Document ? o = n.documentElement[e] : (n instanceof HTMLElement || n) && (o = n[e]), n && !u(n) && typeof o != "number" && (o = (l = ((c = n.ownerDocument) !== null && c !== void 0 ? c : n).documentElement) === null || l === void 0 ? void 0 : l[e]), o;
  16. }
  17. function D(n) {
  18. let i = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
  19. const {
  20. getContainer: c = () => window,
  21. callback: l,
  22. duration: e = 450
  23. } = i, o = c(), m = a(o), d = Date.now(), f = () => {
  24. const s = Date.now() - d, t = p(s > e ? e : s, m, n, e);
  25. u(o) ? o.scrollTo(window.scrollX, t) : o instanceof Document ? o.documentElement.scrollTop = t : o.scrollTop = t, s < e ? r(f) : typeof l == "function" && l();
  26. };
  27. r(f);
  28. }
  29. export {
  30. a as g,
  31. D as s
  32. };