2022-12-06 12:14:45 +00:00
|
|
|
import { Directive } from 'vue'
|
2024-03-16 18:11:08 +00:00
|
|
|
import { useIntersectionObserver } from '@vueuse/core'
|
2022-12-06 12:14:45 +00:00
|
|
|
|
|
|
|
const toggleClasses = (el: HTMLElement) => {
|
|
|
|
el.classList.toggle('fade-top', el.scrollTop !== 0)
|
|
|
|
el.classList.toggle('fade-bottom', el.scrollTop + el.clientHeight !== el.scrollHeight)
|
|
|
|
}
|
|
|
|
|
|
|
|
export const overflowFade: Directive = {
|
|
|
|
mounted: async (el: HTMLElement) => {
|
2024-03-16 18:11:08 +00:00
|
|
|
useIntersectionObserver(el, ([{ isIntersecting }]) => isIntersecting && toggleClasses(el))
|
2022-12-06 12:14:45 +00:00
|
|
|
el.addEventListener('scroll', () => requestAnimationFrame(() => toggleClasses(el)))
|
|
|
|
}
|
|
|
|
}
|