css keyFrame 사용
const { current } = containerRef;
useEffect(() => {
if (current) {
setTimeout(() => {
containerRef.current.scrollLeft =
CardsWrapperRef.current?.offsetWidth / 3;
}, 1000);
}
}, [containerRef, current]);
...
return (
<CardsWrapper
isOverflow={isOverflow}
maxLength={maxLength}
ref={CardsWrapperRef}
>
{[...waffleCards, ...waffleCards, ...waffleCards]?.map(
(waffleCard, index) => (
<StyledWaffleCard
index={index}
type={type}
key={waffleCard.id + index}
waffleCardData={waffleCard}
onClickWaffleCard={handleClickWaffleCard}
onClickLikeToggle={handleClickLikeToggle}
onClickEdit={handleClickWaffleCardEdit}
onClickDelete={handleClickWaffleCardDelete}
/>
),
)}
</CardsWrapper>
);
...
const translate = keyframes`
0% {
transform:translateX(-33.3333%)
}
100% {
transform:translateX(-66.6666%)
}
`;
const CardsWrapper = styled.ul`
...
${({ isOverflow, maxLength }) => {
if (isOverflow) {
return css`
justify-content: left;
animation-name: ${translate};
animation-duration: ${maxLength / 0.8}s;
animation-delay: 1s;
animation-iteration-count: infinite;
animation-timing-function: linear;
animation-direction: normal;
&:hover {
animation-play-state: paused;
}
`;
} else {
return css`
justify-content: center;
`;
}
}};
`;
문제점