Skip to content

Commit a34a015

Browse files
authored
Merge pull request #1134 from Matoseb/master
[Bug]: scrollProgress not tightly synced to container translate
2 parents 2617456 + b0ef3dc commit a34a015

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

packages/embla-carousel/src/components/EmblaCarousel.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ function EmblaCarousel(
188188
}
189189

190190
function scrollProgress(): number {
191-
return engine.scrollProgress.get(engine.location.get())
191+
return engine.scrollProgress.get(engine.offsetLocation.get())
192192
}
193193

194194
function selectedScrollSnap(): number {

packages/embla-carousel/src/components/Engine.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,9 @@ export function Engine(
187187
const shouldSettle = scrollBody.settled()
188188
const withinBounds = !scrollBounds.shouldConstrain()
189189
const hasSettled = loop ? shouldSettle : shouldSettle && withinBounds
190+
const hasSettledAndIdle = hasSettled && !dragHandler.pointerDown()
190191

191-
if (hasSettled && !dragHandler.pointerDown()) {
192-
animation.stop()
193-
eventHandler.emit('settle')
194-
}
195-
if (!hasSettled) eventHandler.emit('scroll')
192+
if (hasSettledAndIdle) animation.stop()
196193

197194
const interpolatedLocation =
198195
location.get() * alpha + previousLocation.get() * (1 - alpha)
@@ -205,6 +202,9 @@ export function Engine(
205202
}
206203

207204
translate.to(offsetLocation.get())
205+
206+
if (hasSettledAndIdle) eventHandler.emit('settle')
207+
if (!hasSettled) eventHandler.emit('scroll')
208208
}
209209

210210
const animation = Animations(

0 commit comments

Comments
 (0)