Skip to content

Commit 8e5a82a

Browse files
committed
feat: support scrollcontrols prepend
1 parent 9099cdf commit 8e5a82a

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,8 @@ type ScrollControlsProps = {
437437
* then a maxSpeed of e.g. 0.1 which will clamp the speed to 0.1 units per second, it may now
438438
* take much longer than damping to reach the target if it is far away. Default: Infinity */
439439
maxSpeed?: number
440+
/** If true attaches the scroll container before the canvas */
441+
prepend?: boolean
440442
enabled?: boolean
441443
style?: React.CSSProperties
442444
children: React.ReactNode

src/web/ScrollControls.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export type ScrollControlsProps = {
2424
* then a maxSpeed of e.g. 3 which will clamp the speed to 3 units per second, it may now
2525
* take much longer than damping to reach the target if it is far away. Default: Infinity */
2626
maxSpeed?: number
27+
/** If true attaches the scroll container before the canvas */
28+
prepend?: boolean
2729
enabled?: boolean
2830
style?: React.CSSProperties
2931
children: React.ReactNode
@@ -59,6 +61,7 @@ export function ScrollControls({
5961
distance = 1,
6062
damping = 0.25,
6163
maxSpeed = Infinity,
64+
prepend = false,
6265
style = {},
6366
children,
6467
}: ScrollControlsProps) {
@@ -126,7 +129,9 @@ export function ScrollControls({
126129
fill.style.width = horizontal ? `${pages * distance * 100}%` : '100%'
127130
fill.style.pointerEvents = 'none'
128131
el.appendChild(fill)
129-
target.appendChild(el)
132+
133+
if (prepend) target.prepend(el)
134+
else target.appendChild(el)
130135

131136
// Init scroll one pixel in to allow upward/leftward scroll
132137
el[horizontal ? 'scrollLeft' : 'scrollTop'] = 1

0 commit comments

Comments
 (0)