Skip to content

Commit 4b7ab55

Browse files
ilyaliaoeavlee
andauthored
fix(useScroll): handle negative scroll values (#4613)
Co-authored-by: eavlee <eavlee@users.noreply.github.com>
1 parent e4d80df commit 4b7ab55

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

packages/core/useInfiniteScroll/index.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,17 @@ function resetList() {
5050
</template>
5151
```
5252

53+
## Direction
54+
55+
Different scroll directions require different CSS style settings:
56+
57+
| Direction | Required CSS |
58+
| ------------------ | ----------------------------------------------------- |
59+
| `bottom` (default) | No special settings required |
60+
| `top` | `display: flex;`<br>`flex-direction: column-reverse;` |
61+
| `left` | `display: flex;`<br>`flex-direction: row-reverse;` |
62+
| `right` | `display: flex;` |
63+
5364
::: warning
5465
Make sure to indicate when there is no more content to load with `canLoadMore`, otherwise `onLoadMore` will trigger as long as there is space for more content.
5566
:::

packages/core/useScroll/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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)