fix(BOOK-496): Slowed down the MarqueeText component animation

Approved-by: Matilda Landström
This commit is contained in:
Erik Tiekstra
2025-11-04 10:29:20 +00:00
parent 59143b4023
commit fa10abbe78
2 changed files with 19 additions and 26 deletions

View File

@@ -52,17 +52,16 @@ export function MarqueeText({
// Calculate dynamic animation duration based on scroll distance // Calculate dynamic animation duration based on scroll distance
// This is done to avoid long scrolling durations for small distances and vice versa // This is done to avoid long scrolling durations for small distances and vice versa
// Base formula: minimum 2s, add 50ms per pixel of scroll distance // Base formula: minimum 4000ms, add 60ms per pixel of scroll distance. The duration
const baseDuration = 2 // includes start and end pauses.
const durationPerPixel = 0.05 const baseDuration = 4000
const calculatedDuration = Math.max( const durationPerPixel = 60
baseDuration, const calculatedDuration =
baseDuration + scrollDistance * durationPerPixel baseDuration + scrollDistance * durationPerPixel
)
parentElement.style.setProperty( parentElement.style.setProperty(
"--animation-duration", "--animation-duration",
`${calculatedDuration}s` `${calculatedDuration}ms`
) )
} }
}) })

View File

@@ -1,4 +1,7 @@
.marqueeText { .marqueeText {
--animation-duration: 14000ms;
--scroll-distance: 0;
--marquee-background-color: transparent;
background-color: var(--marquee-background-color); background-color: var(--marquee-background-color);
position: relative; position: relative;
flex-shrink: 1; flex-shrink: 1;
@@ -21,7 +24,7 @@
z-index: 2; z-index: 2;
pointer-events: none; pointer-events: none;
opacity: 0; opacity: 0;
animation: leftShadow var(--animation-duration, 8s) linear infinite; animation: leftShadow var(--animation-duration) linear infinite;
} }
&::after { &::after {
@@ -39,12 +42,7 @@
z-index: 2; z-index: 2;
pointer-events: none; pointer-events: none;
opacity: 1; opacity: 1;
animation: rightShadow var(--animation-duration, 8s) linear infinite; animation: rightShadow var(--animation-duration) linear infinite;
}
&:has(.overflowing:hover)::before,
&:has(.overflowing:hover)::after {
animation-play-state: paused;
} }
} }
} }
@@ -61,31 +59,27 @@
} }
&.overflowing { &.overflowing {
animation: autoScrollText var(--animation-duration, 8s) ease-in-out infinite; animation: autoScrollText var(--animation-duration) linear infinite;
&:hover {
animation-play-state: paused;
}
} }
} }
@keyframes autoScrollText { @keyframes autoScrollText {
0%, 0%,
15% { 10% {
transform: translateX(0); transform: translateX(0);
} }
80%, 75%,
100% { 100% {
transform: translateX(calc(-1 * var(--scroll-distance, 50px))); transform: translateX(calc(-1 * var(--scroll-distance)));
} }
} }
@keyframes leftShadow { @keyframes leftShadow {
0%, 0%,
16% { 11% {
opacity: 0; opacity: 0;
} }
17%, 12%,
100% { 100% {
opacity: 1; opacity: 1;
} }
@@ -93,10 +87,10 @@
@keyframes rightShadow { @keyframes rightShadow {
0%, 0%,
79% { 74% {
opacity: 1; opacity: 1;
} }
80%, 75%,
100% { 100% {
opacity: 0; opacity: 0;
} }