UNPKG

@extclp/vexip-ui

Version:

A Vue 3 UI library, Highly customizability, full TypeScript, performance pretty good

1 lines 1.6 kB
{"version":3,"file":"helper.mjs","sources":["../../../components/anchor/helper.ts"],"sourcesContent":["export interface ScrollElement {\n scrollTo(x: number, y: number): void,\n [prop: string]: any\n}\n\nexport function animateScrollTo(\n el: ScrollElement,\n from: number,\n to: number,\n duration: number,\n callback: unknown\n): void {\n const distance = to - from\n const step = Math.ceil((distance / duration) * 16)\n\n const end = () => {\n typeof callback === 'function' && callback()\n }\n\n if (!distance) {\n end()\n return\n }\n\n if (duration <= 0) {\n el.scrollTo(0, to)\n end()\n return\n }\n\n let current = from\n\n const scroll = () => {\n if (!distance) return\n\n current = current + step\n\n if ((to - current) / distance <= 0) {\n current = to\n }\n\n el.scrollTo(0, current)\n\n if (current === to) {\n end()\n } else {\n requestAnimationFrame(scroll)\n }\n }\n\n scroll()\n}\n"],"names":["animateScrollTo","el","from","to","duration","callback","distance","step","end","current","scroll"],"mappings":"AAKO,SAASA,EACdC,GACAC,GACAC,GACAC,GACAC,GACM;AACN,QAAMC,IAAWH,IAAKD,GAChBK,IAAO,KAAK,KAAMD,IAAWF,IAAY,EAAE,GAE3CI,IAAM,MAAM;AACT,WAAAH,KAAa,cAAcA,EAAS;AAAA,EAC7C;AAEA,MAAI,CAACC,GAAU;AACT,IAAAE,EAAA;AACJ;AAAA,EAAA;AAGF,MAAIJ,KAAY,GAAG;AACd,IAAAH,EAAA,SAAS,GAAGE,CAAE,GACbK,EAAA;AACJ;AAAA,EAAA;AAGF,MAAIC,IAAUP;AAEd,QAAMQ,IAAS,MAAM;AACnB,IAAKJ,MAELG,IAAUA,IAAUF,IAEfJ,IAAKM,KAAWH,KAAY,MACrBG,IAAAN,IAGTF,EAAA,SAAS,GAAGQ,CAAO,GAElBA,MAAYN,IACVK,EAAA,IAEJ,sBAAsBE,CAAM;AAAA,EAEhC;AAEO,EAAAA,EAAA;AACT;"}