added Back To Top functionality and Pankuzu list, Q and A Box, and Hamburger menu components
This commit is contained in:
29
composables/scrollDistance.ts
Normal file
29
composables/scrollDistance.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Vue Composable for getting scroll distance
|
||||
* @module composables/scrollDistance
|
||||
*/
|
||||
|
||||
/**
|
||||
* Vue Composable for getting scroll distance of client
|
||||
* @returns {globalThis.Ref<number, number>} reference to the scroll distance value
|
||||
*/
|
||||
function useScrollDistance() {
|
||||
const scrollDistance = ref<number>(0);
|
||||
|
||||
function update() {
|
||||
if (import.meta.client) {
|
||||
scrollDistance.value = window.scrollY;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
update();
|
||||
window.addEventListener("scroll", update);
|
||||
});
|
||||
|
||||
onUnmounted(() => window.removeEventListener("scroll", update));
|
||||
|
||||
return scrollDistance;
|
||||
}
|
||||
|
||||
export { useScrollDistance };
|
||||
Reference in New Issue
Block a user