import { Component } from '@angular/core';
import { WrMarquee } from 'ngwr/animations/marquee';
@Component({ imports: [WrMarquee] })
export class MyComponent {}Marquee
A row of links that glides sideways in an endless loop, each item entering under a soft fade at one end and leaving under the other. It stops off screen, while the document is hidden, under the pointer and while focus is in it, and with pausable on a pause button at its end.
Installation
Import the class, and @use the entry point in your global styles. Nothing warns you when the @use is missing.
Basic
items are the links, each a title and a URL, rendered as plain anchors. The belt holds the list twice and one CSS animation slides it by exactly the measured width of one copy, so the frame the cycle ends on is the frame it began on and the seam never shows. The width is read once the row is laid out and again when its size changes, and the duration is that width over speed, so the row moves at the same px per second whatever is in it. label names the list.
protected readonly items: WrMarqueeItem[] = [
{ title: 'Button', url: '/reference/components/button' },
{ title: 'Select', url: '/reference/components/select' },
];<wr-marquee [items]="items" label="Components" />Router links
The library never imports the router, so a routed app projects an <ng-template let-item> with its own anchor and a routerLink on it; the marquee renders it for each item in both copies. The anchor carries wr-marquee__link, the class the stylesheet dresses a link with.
<wr-marquee [items]="items" label="Components">
<ng-template let-item>
<a class="wr-marquee__link" [routerLink]="item.url">{{ item.title }}</a>
</ng-template>
</wr-marquee>Icons in the items
An item is whatever the template draws: a wr-icon before the name makes a row of logos. The link lays its icon and its name out on one line, and the icon takes the link's colour, muted at rest and primary under the pointer. Here the icons are the brand marks this site registers with provideWrIcons.
<wr-marquee [items]="logos" label="Built with">
<ng-template let-item>
<a class="wr-marquee__link" [href]="item.url"><wr-icon [name]="item.icon" />{{ item.title }}</a>
</ng-template>
</wr-marquee>Speed
speed is in px per second, 40 by default. Nothing but translate animates, declared paused and set running by one modifier, so a pause keeps the phase: the row picks up where it stopped.
<wr-marquee [items]="items" label="Components" speed="90" />Pause button
pausable adds a pause button at the end of a row that moves; a still row has none. Without it the row stops under the pointer and while focus is in it, nothing more. The name comes from the i18n catalog (marquee.pause, marquee.play), so an app with ngwr/i18n/de hears "Pausieren"; pauseLabel and playLabel override it for one instance.
<wr-marquee [items]="items" label="Components" pausable /><wr-marquee [items]="items" label="Components" pausable pauseLabel="Hold the row" playLabel="Let it run" />Accessibility
| Part | Behaviour |
|---|---|
| Screen readers | The second copy is aria-hidden and inert, so the list is heard once, as a list of links named by label, and tabbed once. |
| Keyboard | A link that takes focus stops the row: the viewport scrolls natively and the link is brought into view, so what has focus is what can be seen. Leaving the belt resumes the loop from the start of the row. |
| Pausing | The row stops under the pointer, while focus is in it, off screen and while the document is hidden. With pausable it also stops on the pause button, and that pause stays until the button is pressed again. A marquee that runs on for more than five seconds needs a way to stop it (WCAG 2.2.2): pausable provides one, hover and focus pause alone do not. |
| Reduced motion | Under prefers-reduced-motion: reduce the row never moves: one copy, scrollable, under the same fade, with no pause button even with pausable. |
| Server | The one copy is rendered as a still row; the loop starts from the same picture, so nothing shifts. |
| RTL | The belt travels toward the inline start, so under RTL the row runs the other way. |
API
| Name | Description | Type | Default |
|---|---|---|---|
itemsrequired | The links, in the order they pass. | readonly WrMarqueeItem[] | — |
speed | How fast the row travels, in px per second. | number | 40 |
label | The accessible name of the list. | string | null | null |
pausable | Renders the pause button at the row's end, the way to stop a row that runs on (WCAG 2.2.2). Hover and focus pause the row with or without it. | boolean | false |
pauseLabel | The pause button's name while the row moves. Unset, the marquee.pause string of the i18n catalog, "Pause" in English. | string | null | null |
playLabel | The pause button's name while the row stands. Unset, the marquee.play string of the i18n catalog, "Play" in English. | string | null | null |
CSS variables
Set these on the element itself, with a rule more specific than its Declared on selector. In a global stylesheet, put a class of yours on an ancestor it really has: <body> for an overlay panel, which renders outside your markup. In a component stylesheet the selector alone works, but only for an element in that component's own template. A value on a wrapper or :root is shadowed, because ngwr/animations/marquee declares each default on its own element.
| Variable | Default | Declared on |
|---|---|---|
--wr-marquee-color | var(--wr-color-on-surface-muted) | .wr-marquee |
--wr-marquee-color-active | var(--wr-color-primary-ink) | .wr-marquee |
--wr-marquee-dir | -1 | .wr-marquee +1 variant override |
--wr-marquee-dot | var(--wr-border-strong) | .wr-marquee |
--wr-marquee-fade | 3rem | .wr-marquee |
--wr-marquee-gap | 1.25rem | .wr-marquee |
Dependencies
| Built on | Button |
|---|
See also
Animation Rotate RevealOne word of a sentence gives way to the next from a list, in place: the letters leaving rise out of the line while the letters arriving climb in under them, and the slot eases to the new width so the rest of the sentence glides.Component CarouselSlides with previous and next buttons, dots and optional autoplay.Guide TranslateTranslate your app and ngwr's own labels, and switch the locale at runtime.Component ButtonA button for an action or a link.Component IconRenders an SVG icon you register by name; ngwr ships none of its own.