Skip to content

Commit

Permalink
feat(useWindowScroll): add useWindowScroll
Browse files Browse the repository at this point in the history
  • Loading branch information
lmhcoding committed Sep 19, 2020
1 parent 9bc82da commit d1d29fc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .prettierrc
@@ -1,7 +1,7 @@
{
"trailingComma": "es5",
"singleQuote": true,
"printWidth": 120,
"tabWidth": 2,
"semi": false
"semi": false,
"trailingComma": "none"
}
1 change: 1 addition & 0 deletions src/index.ts
@@ -1,2 +1,3 @@
export * from './useTitle'
export * from './useEvent'
export * from './useWindowScroll'
15 changes: 15 additions & 0 deletions 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)
}

0 comments on commit d1d29fc

Please sign in to comment.