feat: add see menu btn

This commit is contained in:
YunYouJun
2022-04-17 01:42:52 +08:00
parent 439f9a080d
commit 7163fd350b
10 changed files with 136 additions and 82 deletions

27
src/composables/helper.ts Normal file
View File

@@ -0,0 +1,27 @@
import { useElementBounding, useIntersectionObserver } from '@vueuse/core'
import type { Ref } from 'vue'
import { ref } from 'vue'
/**
* trigger show invisible element
* @param target
* @returns
*/
export function useInvisibleElement(target: Ref<HTMLElement>) {
const isVisible = ref(false)
const { top } = useElementBounding(target)
useIntersectionObserver(target, ([{ isIntersecting }]) => {
isVisible.value = isIntersecting
})
const show = () => {
// scroll when collapse is not visible
if (!isVisible.value)
window.scrollTo(0, top.value)
}
return {
isVisible,
show,
}
}