Skip to content

Commit

Permalink
round animate to target
Browse files Browse the repository at this point in the history
Fixes never ending lerping when to is not an integer thus never passing the Math.round check to determine animation completion. See https://github.com/studio-freight/lenis/issues/168
  • Loading branch information
Theo Gil committed May 4, 2023
1 parent f95b7f6 commit 0a91cbc
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/animate.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ export class Animate {

// Set up the animation from a starting value to an ending value
// with optional parameters for lerping, duration, easing, and onUpdate callback
// to value is rounded to ensure proper animation completion detection when using lerping
fromTo(from, to, { lerp = 0.1, duration = 1, easing = (t) => t, onUpdate }) {
this.from = this.value = from
this.to = to
this.to = Math.round(to)
this.lerp = lerp
this.duration = duration
this.easing = easing
Expand Down

0 comments on commit 0a91cbc

Please sign in to comment.