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

Function animate

src/ts-default/Animations/LogoLoop/LogoLoop.tsx:145–170  ·  view source on GitHub ↗
(timestamp: number)

Source from the content-addressed store, hash-verified

143 }
144
145 const animate = (timestamp: number) => {
146 if (lastTimestampRef.current === null) {
147 lastTimestampRef.current = timestamp;
148 }
149
150 const deltaTime = Math.max(0, timestamp - lastTimestampRef.current) / 1000;
151 lastTimestampRef.current = timestamp;
152
153 const target = isHovered && hoverSpeed !== undefined ? hoverSpeed : targetVelocity;
154
155 const easingFactor = 1 - Math.exp(-deltaTime / ANIMATION_CONFIG.SMOOTH_TAU);
156 velocityRef.current += (target - velocityRef.current) * easingFactor;
157
158 if (seqSize > 0) {
159 let nextOffset = offsetRef.current + velocityRef.current * deltaTime;
160 nextOffset = ((nextOffset % seqSize) + seqSize) % seqSize;
161 offsetRef.current = nextOffset;
162
163 const transformValue = isVertical
164 ? `translate3d(0, ${-offsetRef.current}px, 0)`
165 : `translate3d(${-offsetRef.current}px, 0, 0)`;
166 track.style.transform = transformValue;
167 }
168
169 rafRef.current = requestAnimationFrame(animate);
170 };
171
172 rafRef.current = requestAnimationFrame(animate);
173

Callers 3

handlePointerUpFunction · 0.50
SliderFunction · 0.50
OrbitImagesFunction · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected