|
|
@ -7,7 +7,7 @@ interface ScrollReturn {
|
|
|
|
scrollRef: Ref<ScrollElement>
|
|
|
|
scrollRef: Ref<ScrollElement>
|
|
|
|
scrollToBottom: () => Promise<void>
|
|
|
|
scrollToBottom: () => Promise<void>
|
|
|
|
scrollToTop: () => Promise<void>
|
|
|
|
scrollToTop: () => Promise<void>
|
|
|
|
scrollToBottomIfAtBottom: () => Promise<void>
|
|
|
|
scrollToBottomIfAtBottom: () => Promise<void>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export function useScroll(): ScrollReturn {
|
|
|
|
export function useScroll(): ScrollReturn {
|
|
|
@ -26,20 +26,19 @@ export function useScroll(): ScrollReturn {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const scrollToBottomIfAtBottom = async () => {
|
|
|
|
const scrollToBottomIfAtBottom = async () => {
|
|
|
|
await nextTick()
|
|
|
|
await nextTick()
|
|
|
|
if (scrollRef.value) {
|
|
|
|
if (scrollRef.value) {
|
|
|
|
const threshold = 50 // 阈值,表示滚动条到底部的距离阈值
|
|
|
|
const threshold = 50 // 阈值,表示滚动条到底部的距离阈值
|
|
|
|
const distanceToBottom = scrollRef.value.scrollHeight - scrollRef.value.scrollTop - scrollRef.value.clientHeight
|
|
|
|
const distanceToBottom = scrollRef.value.scrollHeight - scrollRef.value.scrollTop - scrollRef.value.clientHeight
|
|
|
|
if (distanceToBottom <= threshold) {
|
|
|
|
if (distanceToBottom <= threshold)
|
|
|
|
scrollRef.value.scrollTop = scrollRef.value.scrollHeight
|
|
|
|
scrollRef.value.scrollTop = scrollRef.value.scrollHeight
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
scrollRef,
|
|
|
|
scrollRef,
|
|
|
|
scrollToBottom,
|
|
|
|
scrollToBottom,
|
|
|
|
scrollToTop,
|
|
|
|
scrollToTop,
|
|
|
|
scrollToBottomIfAtBottom,
|
|
|
|
scrollToBottomIfAtBottom,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|