diff --git a/.prettierrc b/.prettierrc index b25adf1..a171b98 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,7 +1,7 @@ { - "trailingComma": "es5", "singleQuote": true, "printWidth": 120, "tabWidth": 2, - "semi": false + "semi": false, + "trailingComma": "none" } \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 89c5161..2ce9aa4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,2 +1,3 @@ export * from './useTitle' export * from './useEvent' +export * from './useWindowScroll' diff --git a/src/useWindowScroll.ts b/src/useWindowScroll.ts new file mode 100644 index 0000000..d84d82a --- /dev/null +++ b/src/useWindowScroll.ts @@ -0,0 +1,15 @@ +import { reactive, toRefs } from 'vue' +import { useEvent } from './useEvent' +import { ScrollState } from './useScroll' + +export function useWindowScroll(): ScrollState { + const state = reactive({ + x: 0, + y: 0 + }) + useEvent('scroll', () => { + state.x = window.scrollX + state.y = window.scrollY + }) + return toRefs(state) +}