Skip to content

Commit b65c69a

Browse files
committed
feat: make testimonial carousel speed constant regardless of count
1 parent b19ca3f commit b65c69a

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

src/pages/index.astro

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ const mixed2 = [...strong2.slice(0, 5), extra2[0], ...strong2.slice(5, 10), extr
1616
// Duplicate for seamless loop
1717
const row1 = [...mixed1, ...mixed1];
1818
const row2 = [...mixed2, ...mixed2];
19+
20+
// Calculate animation duration based on content length for constant speed
21+
// Each card is ~336px (320px min-width + 16px gap), speed = 50px/s
22+
const pixelsPerItem = 336;
23+
const pixelsPerSecond = 50;
24+
const duration1 = (row1.length / 2 * pixelsPerItem) / pixelsPerSecond;
25+
const duration2 = (row2.length / 2 * pixelsPerItem) / pixelsPerSecond;
1926
---
2027

2128
<Layout title="Clawdbot — Personal AI Assistant">
@@ -185,7 +192,7 @@ const row2 = [...mixed2, ...mixed2];
185192
<span class="claw-accent">⟩</span> What People Say
186193
</h2>
187194
<div class="testimonials-track">
188-
<div class="testimonials-row row-1">
195+
<div class="testimonials-row row-1" style={`--duration: ${duration1}s`}>
189196
{row1.map((t) => (
190197
<a href={t.url} target="_blank" rel="noopener" class="testimonial-card">
191198
<img
@@ -201,7 +208,7 @@ const row2 = [...mixed2, ...mixed2];
201208
</a>
202209
))}
203210
</div>
204-
<div class="testimonials-row row-2">
211+
<div class="testimonials-row row-2" style={`--duration: ${duration2}s`}>
205212
{row2.map((t) => (
206213
<a href={t.url} target="_blank" rel="noopener" class="testimonial-card">
207214
<img
@@ -684,11 +691,11 @@ const row2 = [...mixed2, ...mixed2];
684691
}
685692

686693
.row-1 {
687-
animation: scroll-left 80s linear infinite;
694+
animation: scroll-left var(--duration, 80s) linear infinite;
688695
}
689696

690697
.row-2 {
691-
animation: scroll-right 90s linear infinite;
698+
animation: scroll-right var(--duration, 90s) linear infinite;
692699
}
693700

694701
@keyframes scroll-left {

0 commit comments

Comments
 (0)