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

Function animate

src/tailwind/Animations/LogoLoop/LogoLoop.jsx:104–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

102 }
103
104 const animate = timestamp => {
105 if (lastTimestampRef.current === null) {
106 lastTimestampRef.current = timestamp;
107 }
108
109 const deltaTime = Math.max(0, timestamp - lastTimestampRef.current) / 1000;
110 lastTimestampRef.current = timestamp;
111
112 const target = isHovered && hoverSpeed !== undefined ? hoverSpeed : targetVelocity;
113
114 const easingFactor = 1 - Math.exp(-deltaTime / ANIMATION_CONFIG.SMOOTH_TAU);
115 velocityRef.current += (target - velocityRef.current) * easingFactor;
116
117 if (seqSize > 0) {
118 let nextOffset = offsetRef.current + velocityRef.current * deltaTime;
119 nextOffset = ((nextOffset % seqSize) + seqSize) % seqSize;
120 offsetRef.current = nextOffset;
121
122 const transformValue = isVertical
123 ? `translate3d(0, ${-offsetRef.current}px, 0)`
124 : `translate3d(${-offsetRef.current}px, 0, 0)`;
125 track.style.transform = transformValue;
126 }
127
128 rafRef.current = requestAnimationFrame(animate);
129 };
130
131 rafRef.current = requestAnimationFrame(animate);
132

Callers 3

handlePointerUpFunction · 0.50
SliderFunction · 0.50
OrbitImagesFunction · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected