Files
short-drama-agent-front/src/composables/usePanelScrollState.ts
T

23 lines
810 B
TypeScript

import { ref, watch, type Ref } from 'vue'
/**
* 公共弹层仅在正文离开顶部后提示遮挡,重新开关时清除旧状态。
* @param open 当前弹层显隐
* @returns 正文滚动状态与滚动事件入口
*/
export function usePanelScrollState(open: Readonly<Ref<boolean>>) {
/** 只表达正文顶部是否有被遮挡内容,不跟随内部输入框滚动。 */
const bodyScrolled = ref(false)
/**
* 读取真实滚动容器的位置,回到顶部即时隐藏阴影。
* @param event 公共正文滚动事件
*/
function onBodyScroll(event: Event) {
bodyScrolled.value = ((event.target as HTMLElement | null)?.scrollTop ?? 0) > 0
}
watch(open, () => {
bodyScrolled.value = false
})
return { bodyScrolled, onBodyScroll }
}