From 7ed5189f70330a1b046b8e06290697155dd93254 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=9D=E5=85=88=E7=91=9E?= <1490493387@qq.com> Date: Wed, 21 Feb 2024 18:21:12 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20:recycle:=20=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E6=97=A0=E7=94=A8=E5=B7=A5=E5=85=B7=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Pagination/index.vue | 9 ---- src/utils/scroll-to.ts | 69 ----------------------------- 2 files changed, 78 deletions(-) delete mode 100644 src/utils/scroll-to.ts diff --git a/src/components/Pagination/index.vue b/src/components/Pagination/index.vue index 84e8f3e0..4065131e 100644 --- a/src/components/Pagination/index.vue +++ b/src/components/Pagination/index.vue @@ -14,9 +14,6 @@ diff --git a/src/utils/scroll-to.ts b/src/utils/scroll-to.ts deleted file mode 100644 index c4e48fc2..00000000 --- a/src/utils/scroll-to.ts +++ /dev/null @@ -1,69 +0,0 @@ -const easeInOutQuad = (t: number, b: number, c: number, d: number) => { - t /= d / 2; - if (t < 1) { - return (c / 2) * t * t + b; - } - t--; - return (-c / 2) * (t * (t - 2) - 1) + b; -}; - -// requestAnimationFrame for Smart Animating http://goo.gl/sx5sts -const requestAnimFrame = (function () { - return ( - window.requestAnimationFrame || - (window as any).webkitRequestAnimationFrame || - (window as any).mozRequestAnimationFrame || - function (callback) { - window.setTimeout(callback, 1000 / 60); - } - ); -})(); - -/** - * Because it's so fucking difficult to detect the scrolling element, just move them all - * @param {number} amount - */ -const move = (amount: number) => { - document.documentElement.scrollTop = amount; - (document.body.parentNode as HTMLElement).scrollTop = amount; - document.body.scrollTop = amount; -}; - -const position = () => { - return ( - document.documentElement.scrollTop || - (document.body.parentNode as HTMLElement).scrollTop || - document.body.scrollTop - ); -}; - -/** - * @param {number} to - * @param {number} duration - * @param {Function} callback - */ -export const scrollTo = (to: number, duration: number, callback?: any) => { - const start = position(); - const change = to - start; - const increment = 20; - let currentTime = 0; - duration = typeof duration === "undefined" ? 500 : duration; - const animateScroll = function () { - // increment the time - currentTime += increment; - // find the value with the quadratic in-out easing function - const val = easeInOutQuad(currentTime, start, change, duration); - // move the document.body - move(val); - // do the animation unless its over - if (currentTime < duration) { - requestAnimFrame(animateScroll); - } else { - if (callback && typeof callback === "function") { - // the animation is done so lets callback - callback(); - } - } - }; - animateScroll(); -};