Skip to content

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-active control track count, speed, gap, and the on-screen cap
  • add() / addBatch() append items; pause() / resume() / clear() control playback
  • Clicking an item dispatches oas-item-click (detail { text, key, color })
  • The stage is aria-hidden by default; accessible turns it into a role="log" live region
  • Under prefers-reduced-motion the animation duration collapses to instant, with no horizontal drift

Basic Usage ​

Add / pause / clear

Add onePauseClearClick an item to see oas-item-click

Density Control ​

max-active caps on-screen items (0 = unlimited). The example below allows 4, queueing extras until earlier items leave:

max-active=4

Burst 10 items

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 tracks at runtime invalidates and clears on-screen and queued items (track ownership is re-mapped); set the track count at initialization. With auto-play on, the declared items resume on the new tracks immediately (no blank gap).

tracks=1 / speed=80 / gap=120

Add another

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 dispatches oas-like (detail: { text, key, color, liked, count }). Like state is remembered by key (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 is aria-hidden and not focusable (mouse-only, invisible to screen readers). With accessible the stage joins the accessibility tree and the like control becomes a keyboard-reachable role="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 for add / 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)

Send a normal bulletSend an ad bullet
Tap the heart on a bullet; the ad bullet never shows up.

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

Add one (RTL stage)

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 ​

AttributeDescriptionTypeDefault
accessibleBoolean; when present the barrage is exposed to screen readers (role="log" + aria-live="polite"); aria-hidden by default——
auto-playLoop 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-wordsBanned 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 removedstring—
gapMinimum horizontal gap between items on the same track (px, default 48)string—
heightStage height (plain numbers are px, CSS lengths accepted; default 200px)string—
itemsDeclarative 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 attributeArray<string | BarrageItemInput> | string[]
likeableEach 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-activeMaximum on-screen items (0 = unlimited, default 0)string—
pausedControlled pause (present = paused; CSS animations and scheduling timers freeze together)——
speedDrift speed in pixels per second (default 120)string—
tracksTrack count (positive integer, default 3, max 20)string—

Methods ​

MethodSignatureDescription
addadd(text: string, options: BarrageItemOptions): voidAppend one item (options: { color?, key? })
isLikedisLiked(key: string): booleanReads the like state (key = key, or the text when no key; same identity as oas-like)
likeCountlikeCount(key: string): numberReads the like count
addBatchaddBatch(items: Array<string | BarrageItemInput>): voidAppend many (strings or { text, color?, key? })
pausepause(): voidPause (writes the paused attribute)
resumeresume(): voidResume (removes the paused attribute)
clearclear(): voidClear on-screen and queued items; with auto-play on, declared items start rotating again (paused state holds)

Events ​

EventDescription
oas-item-clickDispatched when an item is clicked, detail: { text: item.text, key: item.key, color: item.color }
oas-likeFired when the like control is tapped; detail: { text, key, color, liked, count } (liked is the state after the toggle)

CSS Variables ​

CSS VariableDescriptionDefault
--oas-barrage-bgStage backgroundtransparent
--oas-barrage-colorDefault text colorvar(--oas-color-text-primary)
--oas-barrage-font-sizeBarrage font sizevar(--oas-font-size-md)
--oas-barrage-heightStage height (the height attribute writes the same variable)200px
--oas-barrage-item-bgItem bubble backgroundcolor-mix(in srgb, var(--oas-color-overlay) 24%, transparent)
--oas-barrage-item-colorItem text colorvar(--oas-color-text-primary)
--oas-barrage-item-hover-bgItem hover backgroundcolor-mix(in srgb, var(--oas-color-overlay) 36%, transparent)
--oas-barrage-stage-widthStage width (written by the component for the animation distance)800px
--oas-barrage-tracksTrack count (written by the component)3

Released under the MIT OR Apache-2.0 License.