MCPcopy Create free account
hub / github.com/DavidHDev/react-bits / animate

Function animate

src/content/Animations/LogoLoop/LogoLoop.jsx:79–104  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

77 }
78
79 const animate = timestamp => {
80 if (lastTimestampRef.current === null) {
81 lastTimestampRef.current = timestamp;
82 }
83
84 const deltaTime = Math.max(0, timestamp - lastTimestampRef.current) / 1000;
85 lastTimestampRef.current = timestamp;
86
87 const target = isHovered && hoverSpeed !== undefined ? hoverSpeed : targetVelocity;
88
89 const easingFactor = 1 - Math.exp(-deltaTime / ANIMATION_CONFIG.SMOOTH_TAU);
90 velocityRef.current += (target - velocityRef.current) * easingFactor;
91
92 if (seqSize > 0) {
93 let nextOffset = offsetRef.current + velocityRef.current * deltaTime;
94 nextOffset = ((nextOffset % seqSize) + seqSize) % seqSize;
95 offsetRef.current = nextOffset;
96
97 const transformValue = isVertical
98 ? `translate3d(0, ${-offsetRef.current}px, 0)`
99 : `translate3d(${-offsetRef.current}px, 0, 0)`;
100 track.style.transform = transformValue;
101 }
102
103 rafRef.current = requestAnimationFrame(animate);
104 };
105
106 rafRef.current = requestAnimationFrame(animate);
107

Callers 3

handlePointerUpFunction · 0.50
SliderFunction · 0.50
OrbitImagesFunction · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected