mirror of
https://github.com/koel/koel
synced 2024-12-22 02:23:14 +00:00
18 lines
661 B
TypeScript
18 lines
661 B
TypeScript
import { Directive } from 'vue'
|
|
|
|
const toggleClasses = (el: HTMLElement) => {
|
|
el.classList.toggle('fade-top', el.scrollTop !== 0)
|
|
el.classList.toggle('fade-bottom', el.scrollTop + el.clientHeight !== el.scrollHeight)
|
|
}
|
|
|
|
const observeVisibility = (el: HTMLElement, callback: Closure) => {
|
|
const observer = new IntersectionObserver(entries => entries.forEach(entry => entry.isIntersecting && callback()))
|
|
observer.observe(el)
|
|
}
|
|
|
|
export const overflowFade: Directive = {
|
|
mounted: async (el: HTMLElement) => {
|
|
observeVisibility(el, () => toggleClasses(el))
|
|
el.addEventListener('scroll', () => requestAnimationFrame(() => toggleClasses(el)))
|
|
}
|
|
}
|