From d0e336cbf643b3a76ffae03362cbcee3b8e073aa Mon Sep 17 00:00:00 2001 From: Kelly Horan Date: Tue, 24 Nov 2026 18:18:44 -0600 Subject: [PATCH 1/5] Feature: update nomenclature & css to support vertical animation --- src/lib/marquee.module.css | 24 ++++++++++++++++++++++ src/lib/marquee.tsx | 41 ++++++++++++++++++++++++++++---------- src/main.tsx | 19 ++++++++++++++++++ 3 files changed, 73 insertions(+), 11 deletions(-) diff --git a/src/lib/marquee.module.css b/src/lib/marquee.module.css index c4217321..bf93b832 100644 --- a/src/lib/marquee.module.css +++ b/src/lib/marquee.module.css @@ -8,6 +8,16 @@ } } +@keyframes scroll-vertical { + 0% { + transform: translateY(0%); + } + + 100% { + transform: translateY(calc(var(--marquee-width) * -1px)); + } +} + .Marquee { position: relative; white-space: nowrap; @@ -35,6 +45,20 @@ animation: scroll var(--duration) linear infinite var(--animation-state, running); } +.Marquee--vertical { + animation: scroll-vertical var(--duration) linear infinite + var(--animation-state, running); + + .Marquee__Slide { + display: flex; + flex-direction: column; + } + + .Marquee__Slide > * { + display: block; + } +} + .Marquee--reverse { animation-direction: reverse; } diff --git a/src/lib/marquee.tsx b/src/lib/marquee.tsx index 3f913844..792418a0 100644 --- a/src/lib/marquee.tsx +++ b/src/lib/marquee.tsx @@ -28,9 +28,13 @@ export interface MarqueeProps extends React.ComponentPropsWithoutRef<"div"> { */ speed?: number /** - * Whether to animate from left to right + * Whether to animate from left to right, or bottom to top */ reverse?: boolean + /** + * Whether to animate vertically, from top to bottom + */ + vertical?: boolean } type Timer = ReturnType @@ -41,11 +45,12 @@ export function Marquee({ prefersReducedMotion = false, playing = true, reverse, + vertical, children, className, ...props }: MarqueeProps) { - const [marqueeWidth, setMarqueeWidth] = useState(0) + const [marqueeSize, setmarqueeSize] = useState(0) const [duration, setDuration] = useState(0) const [neededAmount, setNeededAmount] = useState(1) @@ -53,16 +58,29 @@ export function Marquee({ const marquee = useRef(null) const resizeTimer = useRef() + const getRelevantDimensions = () => { + if (vertical) { + return { + containerSize: container.current?.clientHeight || 0, + marqueeSize: marquee.current?.clientHeight || 0, + } + } + + return { + containerSize: container.current?.clientWidth || 0, + marqueeSize: marquee.current?.clientWidth || 0, + } + } + const updateState = useCallback(() => { - const containerWidth = container.current?.clientWidth || 0 - const marqueeWidth = marquee.current?.clientWidth || 0 + const { containerSize, marqueeSize } = getRelevantDimensions() // If prefersReducedMotion, replace speed with reducedMotionSpeed const speedAmount = prefersReducedMotion ? reducedMotionSpeed : speed // Divide the container width, by the marquee width and round it up // to give us the ammount of items needed to fill the container. - let neededAmount = Math.ceil(containerWidth / marqueeWidth) * 2 - 1 + let neededAmount = Math.ceil(containerSize / marqueeSize) * 2 - 1 if (neededAmount < 1 || isNaN(neededAmount) || neededAmount === Infinity) { neededAmount = 1 @@ -73,13 +91,13 @@ export function Marquee({ // Set marquee width in state so we can use it for the`--marquee-width` // inline style. - setMarqueeWidth(marqueeWidth) + setmarqueeSize(marqueeSize) // Set duration speed, which is used below in the --duration inline style. - if (marqueeWidth < containerWidth) { - setDuration(containerWidth / speedAmount) + if (marqueeSize < containerSize) { + setDuration(containerSize / speedAmount) } else { - setDuration(marqueeWidth / speedAmount) + setDuration(marqueeSize / speedAmount) } }, [prefersReducedMotion, reducedMotionSpeed, speed]) @@ -111,13 +129,14 @@ export function Marquee({ ref={container} className={classnames([ styles.Marquee, - marqueeWidth > 0 && styles["Marquee--ready"], + vertical && styles["Marquee--vertical"], + marqueeSize > 0 && styles["Marquee--ready"], reverse && styles["Marquee--reverse"], className, ])} style={ { - "--marquee-width": marqueeWidth, + "--marquee-width": marqueeSize, "--duration": duration + `s`, "--animation-state": playing ? "running" : "paused", } as React.CSSProperties diff --git a/src/main.tsx b/src/main.tsx index c3c3c650..08489643 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -20,6 +20,25 @@ function App() { + +

Vertical

+
+ + + +
+ + {/*

Vertical Reverse

+
+ + + +
*/} ) } From c99189abaeb7056c8345f2ac6d2f7098922f8216 Mon Sep 17 00:00:00 2001 From: Kelly Horan Date: Wed, 25 Nov 2026 11:47:20 -0600 Subject: [PATCH 2/5] Feature: correct issue on firefox & safari --- src/lib/marquee.module.css | 16 +++++++++------- src/lib/marquee.tsx | 2 +- src/main.tsx | 15 +++++---------- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/lib/marquee.module.css b/src/lib/marquee.module.css index bf93b832..3524d1de 100644 --- a/src/lib/marquee.module.css +++ b/src/lib/marquee.module.css @@ -43,20 +43,22 @@ * loading up the animation. */ animation: scroll var(--duration) linear infinite var(--animation-state, running); + + &.Marquee--vertical { + animation: scroll-vertical var(--duration) linear infinite + var(--animation-state, running); + + &.Marquee--reverse { + animation-direction: reverse; + } + } } .Marquee--vertical { - animation: scroll-vertical var(--duration) linear infinite - var(--animation-state, running); - .Marquee__Slide { display: flex; flex-direction: column; } - - .Marquee__Slide > * { - display: block; - } } .Marquee--reverse { diff --git a/src/lib/marquee.tsx b/src/lib/marquee.tsx index 792418a0..4a0e02e5 100644 --- a/src/lib/marquee.tsx +++ b/src/lib/marquee.tsx @@ -32,7 +32,7 @@ export interface MarqueeProps extends React.ComponentPropsWithoutRef<"div"> { */ reverse?: boolean /** - * Whether to animate vertically, from top to bottom + * Whether to animate vertically, from top to bottom. Direct parent node should have display: flex & a defined height (100dvh, etc) */ vertical?: boolean } diff --git a/src/main.tsx b/src/main.tsx index 08489643..6fe1d8ae 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -22,23 +22,18 @@ function App() {

Vertical

-
- +
+
- {/*

Vertical Reverse

-
+

Vertical Reverse

+
-
*/} +
) } From cd0f899758e44865d86a678670c159f233d56520 Mon Sep 17 00:00:00 2001 From: Kelly Horan Date: Wed, 25 Nov 2026 11:47:33 -0600 Subject: [PATCH 3/5] Feature: improve docs --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b04fc52e..5c09bbad 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,8 @@ const YourComponent = () => { | reducedMotionSpeed | Number | 20 | A customisable value used to set the speed of the component if `prefersReducedMotion` is true. | | prefersReducedMotion | Boolean | false | Whether the user prefers reduced motion. If `true`, the component will default to a much slower speed, unless a custom speed is specified using: `reducedMotionSpeed`. | | playing | Boolean | true | Whether the marquee animation is playing or paused. | -| reverse | Boolean | false | Whether the marquee should animate from left to right. | +| reverse | Boolean | false | Whether the marquee should animate from left to right (or top to bottom, if `vertical` is passed as a prop). | +| vertical | Boolean | false | Whether the marquee should animate from bottom to top. __IMPORTANT__: for vertical marquees to work, the direct parent element of the marquee *must* have a defined height (100dvh, etc) and use `display: flex` (and, likely, `overflow: clip`) | className | String | | Optional class added to the parent element. | | children | Node | | The child elements rendered within the component. In the example above these are images, however they can be any type of element. | From c4396e16e4ef9f91e27ff25203a095f99c5c26d7 Mon Sep 17 00:00:00 2001 From: Kelly Horan Date: Wed, 25 Nov 2026 11:54:22 -0600 Subject: [PATCH 4/5] Feature: changeset update --- .changeset/every-worms-crash.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/every-worms-crash.md diff --git a/.changeset/every-worms-crash.md b/.changeset/every-worms-crash.md new file mode 100644 index 00000000..5fb5d6b7 --- /dev/null +++ b/.changeset/every-worms-crash.md @@ -0,0 +1,5 @@ +--- +"@wethegit/react-marquee": minor +--- + +Adds an optional prop to enable vertical marquee functionality. From e624c526088f626c43417d67027b4a9cc73b48cd Mon Sep 17 00:00:00 2001 From: Kelly Horan Date: Wed, 25 Nov 2026 14:28:50 -0600 Subject: [PATCH 5/5] Feature: move getRelevantDimensions into callback, add sanity check of viewport size --- src/lib/marquee.tsx | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/lib/marquee.tsx b/src/lib/marquee.tsx index 4a0e02e5..1f4b4c5e 100644 --- a/src/lib/marquee.tsx +++ b/src/lib/marquee.tsx @@ -58,21 +58,21 @@ export function Marquee({ const marquee = useRef(null) const resizeTimer = useRef() - const getRelevantDimensions = () => { - if (vertical) { - return { - containerSize: container.current?.clientHeight || 0, - marqueeSize: marquee.current?.clientHeight || 0, + const updateState = useCallback(() => { + const getRelevantDimensions = () => { + if (vertical) { + return { + containerSize: container.current?.clientHeight || 0, + marqueeSize: marquee.current?.clientHeight || 0, + } } - } - return { - containerSize: container.current?.clientWidth || 0, - marqueeSize: marquee.current?.clientWidth || 0, + return { + containerSize: container.current?.clientWidth || 0, + marqueeSize: marquee.current?.clientWidth || 0, + } } - } - const updateState = useCallback(() => { const { containerSize, marqueeSize } = getRelevantDimensions() // If prefersReducedMotion, replace speed with reducedMotionSpeed @@ -80,7 +80,14 @@ export function Marquee({ // Divide the container width, by the marquee width and round it up // to give us the ammount of items needed to fill the container. - let neededAmount = Math.ceil(containerSize / marqueeSize) * 2 - 1 + const viewportSize = vertical ? window.innerHeight : window.innerWidth + let neededAmount = + Math.min( + Math.ceil(containerSize / marqueeSize), + Math.ceil(viewportSize / marqueeSize) + ) * + 2 - + 1 if (neededAmount < 1 || isNaN(neededAmount) || neededAmount === Infinity) { neededAmount = 1 @@ -99,7 +106,7 @@ export function Marquee({ } else { setDuration(marqueeSize / speedAmount) } - }, [prefersReducedMotion, reducedMotionSpeed, speed]) + }, [prefersReducedMotion, reducedMotionSpeed, speed, vertical]) useEffect(() => { const el = container.current