mirror of
https://github.com/koel/koel
synced 2024-12-22 10:33:16 +00:00
24 lines
523 B
TypeScript
24 lines
523 B
TypeScript
/**
|
|
* A utility that aims to replace jQuery for the most basic DOM methods.
|
|
*/
|
|
export const $ = {
|
|
scrollTo (el: Element, to: number, duration: number, cb?: Closure) {
|
|
if (duration <= 0 || !el) {
|
|
return
|
|
}
|
|
|
|
const difference = to - el.scrollTop
|
|
const perTick = difference / duration * 10
|
|
|
|
window.setTimeout(() => {
|
|
el.scrollTop = el.scrollTop + perTick
|
|
|
|
if (el.scrollTop === to) {
|
|
cb && cb()
|
|
return
|
|
}
|
|
|
|
this.scrollTo(el, to, duration - 10)
|
|
}, 10)
|
|
}
|
|
}
|