Skip to content

Commit 8633407

Browse files
committed
refactor: remove throttleTime option from mouseWheel configuration and simplify wheel event handling in Carousel
1 parent 1e05296 commit 8633407

File tree

3 files changed

+6
-26
lines changed

3 files changed

+6
-26
lines changed

docs/config.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ The `mouseWheel` property accepts either a boolean value or a `WheelConfig` obje
6161
| Property | Type | Default | Description |
6262
|---------------|----------|---------|--------------------------------------------------------------------------------------------|
6363
| `threshold` | `number` | 10 | Controls the wheel movement threshold required to trigger a slide transition. Higher values require more scrolling to trigger a slide change. |
64-
| `throttleTime` | `number` | 100 | Controls how quickly wheel events are processed in milliseconds. Lower values make scrolling more responsive but may cause performance issues. By default, uses either this value or 1/3 of the transition time, whichever is smaller. |
64+
6565

6666
### Example
6767

6868
```vue
6969
<template>
7070
<Carousel
71-
:mouseWheel="{ threshold: 20, throttleTime: 50 }"
71+
:mouseWheel="{ threshold: 20 }"
7272
>
7373
<!-- Slides -->
7474
</Carousel>

src/composables/useWheel.ts

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import { ComputedRef, Ref, computed } from 'vue'
22

33
import { CarouselConfig } from '@/shared'
4-
import {
5-
DEFAULT_MOUSE_WHEEL_THRESHOLD,
6-
DEFAULT_WHEEL_THROTTLE_TIME,
7-
} from '@/shared/constants'
8-
import { throttle } from '@/utils'
4+
import { DEFAULT_MOUSE_WHEEL_THRESHOLD } from '@/shared/constants'
95

106
interface UseWheelOptions {
117
isVertical: boolean | ComputedRef<boolean>
@@ -32,28 +28,13 @@ export function useWheel(options: UseWheelOptions) {
3228
return typeof isSliding === 'boolean' ? isSliding : isSliding.value
3329
})
3430

35-
// Use a shorter throttle duration for wheel events to improve responsiveness
36-
// Use either a custom wheel throttle time or 1/3 of the transition time
37-
const wheelThrottleTime = computed(() => {
38-
// If mouseWheel is an object with a throttleTime property, use that
39-
if (typeof config.mouseWheel === 'object' && config.mouseWheel.throttleTime) {
40-
return config.mouseWheel.throttleTime
41-
}
42-
// Otherwise use a fraction of the transition time for better responsiveness
43-
return Math.min(
44-
DEFAULT_WHEEL_THROTTLE_TIME,
45-
config.transition ? Math.floor(config.transition / 3) : DEFAULT_WHEEL_THROTTLE_TIME
46-
)
47-
})
31+
const handleScroll = (event: Event): void => {
32+
event.preventDefault()
4833

49-
const handleScroll = throttle((event: Event): void => {
5034
if (!config.mouseWheel || sliding.value) {
5135
return
5236
}
5337

54-
// Prevent default scrolling behavior when wheel navigation is enabled
55-
event.preventDefault()
56-
5738
const wheelEvent = event as WheelEvent
5839

5940
// Add sensitivity threshold to prevent small movements from triggering navigation
@@ -97,7 +78,7 @@ export function useWheel(options: UseWheelOptions) {
9778
prev()
9879
}
9980
}
100-
}, wheelThrottleTime.value) // Use the computed throttle time
81+
}
10182

10283
return {
10384
handleScroll,

src/shared/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ export const SNAP_ALIGN_OPTIONS = [
4646
] as const
4747

4848
export const DEFAULT_MOUSE_WHEEL_THRESHOLD = 10
49-
export const DEFAULT_WHEEL_THROTTLE_TIME = 100
5049
export const DEFAULT_DRAG_THRESHOLD = 0.3
5150

5251
export const DEFAULT_CONFIG: CarouselConfig = {

0 commit comments

Comments
 (0)