UNPKG

@extclp/vexip-ui

Version:

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

1 lines 1.71 kB
{"version":3,"file":"helper.mjs","sources":["../../../components/anchor/helper.ts"],"sourcesContent":["export interface ScrollElement {\r\n scrollTo(x: number, y: number): void,\r\n [prop: string]: any,\r\n}\r\n\r\nexport function animateScrollTo(\r\n el: ScrollElement,\r\n from: number,\r\n to: number,\r\n duration: number,\r\n callback: unknown,\r\n): void {\r\n const distance = to - from\r\n const step = Math.ceil((distance / duration) * 16)\r\n\r\n const end = () => {\r\n typeof callback === 'function' && callback()\r\n }\r\n\r\n if (!distance) {\r\n end()\r\n return\r\n }\r\n\r\n if (duration <= 0) {\r\n el.scrollTo(0, to)\r\n end()\r\n return\r\n }\r\n\r\n let current = from\r\n\r\n const scroll = () => {\r\n if (!distance) return\r\n\r\n current = current + step\r\n\r\n if ((to - current) / distance <= 0) {\r\n current = to\r\n }\r\n\r\n el.scrollTo(0, current)\r\n\r\n if (current === to) {\r\n end()\r\n } else {\r\n requestAnimationFrame(scroll)\r\n }\r\n }\r\n\r\n scroll()\r\n}\r\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;"}