Web Animations Easy
Infinite Marquee (GSAP)
A butter-smooth infinite marquee powered by GSAP ticker. Dynamically fills the viewport width with cloned items and reverses direction on hover.
gsap
Targets: JS HTML
Code
Infinite Marquee (GSAP)
A silky-smooth infinite ticker using GSAP’s gsap.ticker and x transform — no CSS translateX, no duplicate DOM nodes required. Items are cloned dynamically to fill the viewport.
How it works
- Clone track items until the total width exceeds the viewport
- On each ticker frame, increment an
xPosvalue byspeed - When
xPosreaches-originalWidth, reset to0— seamless loop
gsap.ticker.add(() => {
xPos -= speed;
if (xPos <= -origW) xPos = 0;
track.style.transform = `translateX(${xPos}px)`;
});
vs CSS marquee (lg-infinite-marquee)
| CSS marquee | GSAP marquee | |
|---|---|---|
| Speed control | CSS var | JS variable |
| Reverse on hover | CSS | GSAP gsap.to(speed) |
| Velocity easing | ❌ | ✅ (ease in/out of speed) |
| DOM cloning | Manual duplicate | Auto-fill viewport |