Skip to content

Commit

Permalink
fix(useMouse): record the previous scroll value (#4244)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <[email protected]>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 19, 2024
1 parent 0f11df1 commit e8d1189
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/core/useMouse/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ export function useMouse(options: UseMouseOptions = {}) {
} = options

let _prevMouseEvent: MouseEvent | null = null
let _prevScrollX = 0
let _prevScrollY = 0

const x = ref(initialValue.x)
const y = ref(initialValue.y)
Expand All @@ -97,6 +99,11 @@ export function useMouse(options: UseMouseOptions = {}) {
[x.value, y.value] = result
sourceType.value = 'mouse'
}

if (window) {
_prevScrollX = window.scrollX
_prevScrollY = window.screenY
}
}

const touchHandler = (event: TouchEvent) => {
Expand All @@ -115,8 +122,8 @@ export function useMouse(options: UseMouseOptions = {}) {
const pos = extractor(_prevMouseEvent)

if (_prevMouseEvent instanceof MouseEvent && pos) {
x.value = pos[0] + window.scrollX
y.value = pos[1] + window.scrollY
x.value = pos[0] + window.scrollX - _prevScrollX
y.value = pos[1] + window.scrollY - _prevScrollY
}
}

Expand Down

0 comments on commit e8d1189

Please sign in to comment.