anime_text: Specify discrete text keyframes for an element

View source: R/text.R

anime_textR Documentation

Specify discrete text keyframes for an element

Description

Constructs a text-swap specification for use in the props argument of anime_add(). Unlike a numeric tween, a text prop does not interpolate: the values are spread evenly across the segment's duration and the target element's textContent is swapped to the value for the current position as the timeline plays or is scrubbed. Useful for animated titles, counters, and tickers.

Usage

anime_text(values)

Arguments

values

An atomic vector of the successive text values. Non-character vectors are coerced with as.character(), so pre-format numbers (e.g. with format() or formatC()) if you need thousands separators or fixed notation.

Details

The segment's selector picks the text element(s) to update, so the prop name you file this under is only a label; use something descriptive such as text or label.

Value

An anime_text object.

Examples

# A counter that steps through four values across the segment
anime_add(
  anime_timeline(),
  selector = anime_target_id("counter"),
  props = list(text = anime_text(c("0", "25", "50", "100")))
)

# Compose a text swap with an ordinary tween on the same segment
anime_add(
  anime_timeline(),
  selector = anime_target_id("title"),
  props = list(
    opacity = anime_keyframes(0, 1),
    label = anime_text(c("Loading", "Ready"))
  )
)


animejs documentation built on Aug. 21, 2026, 5:17 p.m.