Tiny implementation of spring animation with mass set to 1.
Size: 301 bytes before compression.
Both stiffness and damping must be greater than 0, otherwise the animation never ends.
The function returned by spring cancels the animation, done is not called in that case.
Installation
npm i -S @bluecateng/nano-spring
Example
import spring from '@bluecateng/nano-spring';
const element = document.querySelector('#test');
element.style.opacity = 0.5;
spring(
250,
30,
(p) => (element.style.transform = `translateX(${p * 300}px)`),
() => (element.style.opacity = '')
);