2
0
Fork 0
mirror of https://github.com/koel/koel synced 2024-12-29 14:03:06 +00:00
koel/resources/assets/js/utils/$.ts

25 lines
523 B
TypeScript
Raw Normal View History

2022-04-15 14:24:30 +00:00
/**
* A utility that aims to replace jQuery for the most basic DOM methods.
*/
export const $ = {
scrollTo (el: Element, to: number, duration: number, cb?: Closure) {
2022-04-15 14:24:30 +00:00
if (duration <= 0 || !el) {
return
}
const difference = to - el.scrollTop
const perTick = difference / duration * 10
2022-04-25 16:38:33 +00:00
window.setTimeout(() => {
2022-04-15 14:24:30 +00:00
el.scrollTop = el.scrollTop + perTick
if (el.scrollTop === to) {
cb && cb()
return
}
this.scrollTo(el, to, duration - 10)
}, 10)
}
}