zzz6519003 / blog

My blog about coding
4 stars 1 forks source link

"Lerp" tactic #70

Open zzz6519003 opened 7 years ago

zzz6519003 commented 7 years ago

https://codepen.io/rachsmith/post/animation-tip-lerp https://css-tricks.com/animated-intro-rxjs/#comment-1607034

Essentially, instead of jumping from point A to B, LERP will go a fraction of the way on every animation tick. This produces a smooth transition, even when mouse/touch motion has stopped.

function lerp(start, end) {
  const dx = end.x - start.x;
  const dy = end.y - start.y;

  return {
    x: start.x + dx * 0.1,
    y: start.y + dy * 0.1,
  };
}