AnimationComponentCSSAdded in v15.7

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.

import { Component } from '@angular/core';
import { WrMarquee } from 'ngwr/animations/marquee';

@Component({ imports: [WrMarquee] })
export class MyComponent {}

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.

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

PartBehaviour
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.
ServerThe one copy is rendered as a still row; the loop starts from the same picture, so nothing shifts.
RTLThe belt travels toward the inline start, so under RTL the row runs the other way.

API

NameDescriptionTypeDefault
itemsrequiredThe links, in the order they pass.readonly WrMarqueeItem[]—
speedHow fast the row travels, in px per second.number40
labelThe accessible name of the list.string | nullnull
pausableRenders 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.booleanfalse
pauseLabelThe pause button's name while the row moves. Unset, the marquee.pause string of the i18n catalog, "Pause" in English.string | nullnull
playLabelThe pause button's name while the row stands. Unset, the marquee.play string of the i18n catalog, "Play" in English.string | nullnull

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.

VariableDefaultDeclared on
--wr-marquee-colorvar(--wr-color-on-surface-muted).wr-marquee
--wr-marquee-color-activevar(--wr-color-primary-ink).wr-marquee
--wr-marquee-dir-1.wr-marquee +1 variant override
--wr-marquee-dotvar(--wr-border-strong).wr-marquee
--wr-marquee-fade3rem.wr-marquee
--wr-marquee-gap1.25rem.wr-marquee

Dependencies

Built onButton

See also