Skip to content

Commit

Permalink
fix(useWindowScroll): use scrollX instead of pageXOffset (#2776)
Browse files Browse the repository at this point in the history
  • Loading branch information
okxiaoliang4 committed Feb 16, 2023
1 parent 30bdda6 commit e490aef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
6 changes: 0 additions & 6 deletions packages/core/useWindowScroll/index.md
@@ -1,13 +1,7 @@
---
category: Elements
deprecated: true
---

::: warning
**Deprecated**. Please use `usescroll` instead.
:::


# useWindowScroll

Reactive window scroll
Expand Down
13 changes: 8 additions & 5 deletions packages/core/useWindowScroll/index.ts
Expand Up @@ -4,7 +4,10 @@ import type { ConfigurableWindow } from '../_configurable'
import { defaultWindow } from '../_configurable'

/**
* @deprecated Please use [`usescroll`](https://vueuse.org/core/usescroll/#usescroll) instead.
* Reactive window scroll.
*
* @see https://vueuse.org/useWindowScroll
* @param options
*/
export function useWindowScroll({ window = defaultWindow }: ConfigurableWindow = {}) {
if (!window) {
Expand All @@ -14,15 +17,15 @@ export function useWindowScroll({ window = defaultWindow }: ConfigurableWindow =
}
}

const x = ref(window.pageXOffset)
const y = ref(window.pageYOffset)
const x = ref(window.scrollX)
const y = ref(window.scrollY)

useEventListener(
window,
'scroll',
() => {
x.value = window.pageXOffset
y.value = window.pageYOffset
x.value = window.scrollX
y.value = window.scrollY
},
{
capture: false,
Expand Down

0 comments on commit e490aef

Please sign in to comment.