Barrage
Streaming barrage: each item occupies a track and drifts from right to left at a constant speed; the same track schedules items after "previous item fully entered + minimum gap", preventing rear-end overlaps; max-active caps on-screen density, with extras queued.
tracks/speed/gap/max-activecontrol track count, speed, gap, and the on-screen capadd()/addBatch()append items;pause()/resume()/clear()control playback- Clicking an item dispatches
oas-item-click(detail{ text, key, color }) - The stage is
aria-hiddenby default;accessibleturns it into arole="log"live region - Under
prefers-reduced-motionthe animation duration collapses to instant, with no horizontal drift
Basic Usage
Add / pause / clear
Density Control
max-active caps on-screen items (0 = unlimited). The example below allows 4, queueing extras until earlier items leave:
max-active=4
Single Track
With tracks="1" all items share one track and scheduling guarantees no overlap — suitable for narrow areas or slower reading. gap sets the minimum horizontal gap between consecutive items on the same track (after the previous item has fully entered):
Changing
tracksat runtime invalidates and clears on-screen and queued items (track ownership is re-mapped); set the track count at initialization. Withauto-playon, the declared items resume on the new tracks immediately (no blank gap).
tracks=1 / speed=80 / gap=120
Declarative items and auto-play
items declares the bullets as a JSON array (strings or { text, color?, key? }), aligned with addBatch: when the attribute changes, new entries are batch-enqueued (append semantics; on-screen items are kept). A same-name property channel exists as well (assigning an array serializes and reflects the attribute automatically), so framework bindings need no manual JSON.stringify. auto-play loops the stream: once every declared item of the current round has finished playing (queue empty and no looping item on stage) they re-enqueue automatically (only items-declared data loops — bullets added via add() are not part of the loop; clear() only clears on-screen and queued items, so to stop for good remove items or auto-play):
items + auto-play loop
Likes and banned words
likeable: every bullet carries a heart control; tapping it toggles the like state and dispatchesoas-like(detail: { text, key, color, liked, count }). Like state is remembered bykey(text when no key) across the item lifecycle — when the same key re-enters, it is still liked and the count is kept;isLiked(key)/likeCount(key)let the host mirror it. Without this attribute the rendering is byte-identical to before (zero visual drift).- Accessibility: by default bullets are decorative (stage
aria-hidden), so the like control isaria-hiddenand not focusable (mouse-only, invisible to screen readers). Withaccessiblethe stage joins the accessibility tree and the like control becomes a keyboard-reachablerole="button"(aria-pressed+ i18n accessible name); the item itself no longer carries button semantics, avoiding nested interactive controls. banned-words: comma-separated words (full-width commas work too) or a JSON array string, case-insensitive. Matching bullets are never queued or rendered (the same rule foradd/addBatch/items/ auto-play refill — four enqueue channels, one gate); items already on stage are not retroactively removed, and words added later apply to subsequent bullets.
likeable + banned-words (bullets with 'ad' are filtered)
Writing Direction (RTL)
On RTL pages (ancestor dir="rtl", oas-config-provider direction="rtl", or an RTL locale such as Arabic) items enter from the left and fly out to the right — the mirrored keyframes switch automatically via data-rtl, matching the reading direction:
dir=rtl: enter from the left, exit to the right
Detach and re-attach
When the host leaves the document and comes back (route caching, conditional rendering, collapsed panels), the on-screen items are kept. Each one is re-timed from its remaining duration (endAt - now): the CSS animation is re-positioned through a negative animation-delay so it continues from the correct progress and stays aligned with the JS exit timer — items neither restart from the entry edge nor linger. Items whose time already expired while detached leave immediately on re-attach, freeing their tracks for queued items; re-attaching while paused stays paused and keeps the paused progress.
Methods
See the "Methods" table in the API section below (add / addBatch / pause / resume / clear).
API
oas-barrage
Attributes
| Attribute | Description | Type | Default |
|---|---|---|---|
accessible | Boolean; when present the barrage is exposed to screen readers (role="log" + aria-live="polite"); aria-hidden by default | — | — |
auto-play | Loop playback: once every declared item of the current round has finished playing (queue empty and no looping item on stage), items re-enqueue automatically (only items-declared data loops); after clear() the declared items start rotating again (paused state holds), remove items or auto-play to stop for good | — | — |
banned-words | Banned words (comma-separated or a JSON array string; case-insensitive): matching bullets are never queued or rendered (same rule for add / addBatch / items / auto-play refill — four enqueue channels, one gate); on-screen items are not retroactively removed | string | — |
gap | Minimum horizontal gap between items on the same track (px, default 48) | string | — |
height | Stage height (plain numbers are px, CSS lengths accepted; default 200px) | string | — |
items | Declarative bullet data (JSON array of strings or { text, color?, key? }) aligned with addBatch: attribute changes batch-enqueue the new entries (append semantics, on-screen items kept); a same-name get/set accessor reflects arrays to the attribute | Array<string | BarrageItemInput> | string | [] |
likeable | Each bullet carries a heart like control (tapping toggles the like state and dispatches oas-like; state is remembered by key / text across the item lifecycle) | — | — |
max-active | Maximum on-screen items (0 = unlimited, default 0) | string | — |
paused | Controlled pause (present = paused; CSS animations and scheduling timers freeze together) | — | — |
speed | Drift speed in pixels per second (default 120) | string | — |
tracks | Track count (positive integer, default 3, max 20) | string | — |
Methods
| Method | Signature | Description |
|---|---|---|
add | add(text: string, options: BarrageItemOptions): void | Append one item (options: { color?, key? }) |
isLiked | isLiked(key: string): boolean | Reads the like state (key = key, or the text when no key; same identity as oas-like) |
likeCount | likeCount(key: string): number | Reads the like count |
addBatch | addBatch(items: Array<string | BarrageItemInput>): void | Append many (strings or { text, color?, key? }) |
pause | pause(): void | Pause (writes the paused attribute) |
resume | resume(): void | Resume (removes the paused attribute) |
clear | clear(): void | Clear on-screen and queued items; with auto-play on, declared items start rotating again (paused state holds) |
Events
| Event | Description |
|---|---|
oas-item-click | Dispatched when an item is clicked, detail: { text: item.text, key: item.key, color: item.color } |
oas-like | Fired when the like control is tapped; detail: { text, key, color, liked, count } (liked is the state after the toggle) |
CSS Variables
| CSS Variable | Description | Default |
|---|---|---|
--oas-barrage-bg | Stage background | transparent |
--oas-barrage-color | Default text color | var(--oas-color-text-primary) |
--oas-barrage-font-size | Barrage font size | var(--oas-font-size-md) |
--oas-barrage-height | Stage height (the height attribute writes the same variable) | 200px |
--oas-barrage-item-bg | Item bubble background | color-mix(in srgb, var(--oas-color-overlay) 24%, transparent) |
--oas-barrage-item-color | Item text color | var(--oas-color-text-primary) |
--oas-barrage-item-hover-bg | Item hover background | color-mix(in srgb, var(--oas-color-overlay) 36%, transparent) |
--oas-barrage-stage-width | Stage width (written by the component for the animation distance) | 800px |
--oas-barrage-tracks | Track count (written by the component) | 3 |