Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fc37272

Browse filesBrowse files
ilyaliaoeavlee
andcommitted
fix(useScroll): handle negative scroll values
Co-authored-by: eavlee <eavlee@users.noreply.github.com>
1 parent 636b866 commit fc37272
Copy full SHA for fc37272

File tree

1 file changed

+6
-6
lines changed
Filter options

1 file changed

+6
-6
lines changed

‎packages/core/useScroll/index.ts

Copy file name to clipboardExpand all lines: packages/core/useScroll/index.ts
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ export function useScroll(
145145
})
146146
const scrollContainer
147147
= (_element as Window)?.document?.documentElement
148-
|| (_element as Document)?.documentElement
149-
|| (_element as Element)
148+
|| (_element as Document)?.documentElement
149+
|| (_element as Element)
150150
if (x != null)
151151
internalX.value = scrollContainer.scrollLeft
152152
if (y != null)
@@ -198,8 +198,8 @@ export function useScroll(
198198
directions.left = scrollLeft < internalX.value
199199
directions.right = scrollLeft > internalX.value
200200

201-
const left = (scrollLeft * directionMultipler) <= (offset.left || 0)
202-
const right = (scrollLeft * directionMultipler)
201+
const left = Math.abs(scrollLeft * directionMultipler) <= (offset.left || 0)
202+
const right = Math.abs(scrollLeft * directionMultipler)
203203
+ el.clientWidth >= el.scrollWidth
204204
- (offset.right || 0)
205205
- ARRIVED_STATE_THRESHOLD_PIXELS
@@ -223,8 +223,8 @@ export function useScroll(
223223

224224
directions.top = scrollTop < internalY.value
225225
directions.bottom = scrollTop > internalY.value
226-
const top = scrollTop <= (offset.top || 0)
227-
const bottom = scrollTop
226+
const top = Math.abs(scrollTop) <= (offset.top || 0)
227+
const bottom = Math.abs(scrollTop)
228228
+ el.clientHeight >= el.scrollHeight
229229
- (offset.bottom || 0)
230230
- ARRIVED_STATE_THRESHOLD_PIXELS

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.