Skip to content

Commit

Permalink
Merge pull request #2225 from graphcommerce-org/fix/overlay
Browse files Browse the repository at this point in the history
Fix for overlay stuck in animation loop
  • Loading branch information
paales authored Mar 18, 2024
2 parents 10fa16e + 29407d2 commit e551ffd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/silly-hotels-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphcommerce/framer-scroller": patch
---

Fixed a bug on Firefox in which all overlays would retrigger the scrollTo function on opening or closing.
8 changes: 6 additions & 2 deletions packages/framer-scroller/hooks/useScrollTo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,13 @@ export function useScrollTo() {

if (Array.isArray(incoming)) {
const checkPositions = getScrollSnapPositions()
if (checkPositions.x[incoming[0]] !== to.x || checkPositions.y[incoming[1]] !== to.y)
await scrollTo(incoming, options, __retrigger + 1)
// We check if the value is close enough, since firefox does not round in whole pixels. Values in in`to` could be > 0 but < 1
const closeEnoughX = checkPositions.x.some((x) => Math.abs(x - to.x) <= 1)
const closeEnoughY = checkPositions.y.some((y) => Math.abs(y - to.y) <= 1)

if (!closeEnoughX || !closeEnoughY) await scrollTo(incoming, options, __retrigger + 1)
}

enableSnap()
},
[scrollerRef, enableSnap, getScrollSnapPositions, disableSnap, register, scroll, duration],
Expand Down

0 comments on commit e551ffd

Please sign in to comment.