Text Highlight <mv-text-highlight>

Resalta las palabras cuando entran en el área visible: un trazo de rotulador que recorre las líneas, o una anotación dibujada a mano (subrayado, círculo, recuadro, tachado) trazo a trazo.

CategoríaTexto animado
TipoWeb Component (<mv-text-highlight>)
Estadoestable
Keywordshighlight, marker, underline, annotation, rough, hand-drawn, emphasis

When to use

  • Key phrases in marketing copy should get a marker stroke as they scroll into view
  • A hand-drawn underline, circle, box or strike-through should annotate a short phrase
  • Several annotations should draw in sequence using staggered delays

Avoid when

  • Circle or box annotations would wrap long multi-line passages; they are meant for short phrases
  • A highlighter should glide between phrases of a sentence on hover → use Rolling Text instead
  • A whole paragraph should light up progressively with scroll position → use Scroll Text instead

Instalación

node scripts/add.mjs text-highlight --out ./src/marvelous

Agente de IA con el servidor MCP de Marvelous UI: install_components({ slugs: ["text-highlight"], target_dir: "<absolute path>/src/marvelous", framework: "react" }).

Archivos copiados (dependencias incluidas): tokens/tokens.css, core/base.css, core/element.js, core/motion.js, core/observe.js, components/text-highlight/text-highlight.js, components/text-highlight/text-highlight.css.

Uso

Marcado de referencia: parte de él y personalízalo con atributos, data-* y variables CSS:

<div id="th-demo" style="display:grid;gap:1.75rem;max-width:40rem;text-align:center">
  <p style="margin:0;font:700 clamp(1.6rem,3.6vw,2.3rem)/1.35 var(--mv-font-sans);letter-spacing:-.025em">
    Your customers deserve answers <mv-text-highlight>in seconds</mv-text-highlight>,
    not <mv-text-highlight effect="strike" color="var(--mv-danger)" delay="700">in three days</mv-text-highlight>.
  </p>

  <p style="margin:0;font-size:1.125rem;line-height:1.9;color:var(--mv-fg-muted)">
    Centralize your tickets, <mv-text-highlight effect="underline" delay="200" style="color:var(--mv-fg)">automate replies</mv-text-highlight>
    to recurring questions and keep your team <mv-text-highlight effect="circle" color="var(--mv-warning)" delay="600" duration="1100" style="color:var(--mv-fg)">focused</mv-text-highlight>
    on what matters: <mv-text-highlight effect="box" color="var(--mv-info)" delay="1000" style="color:var(--mv-fg)">people</mv-text-highlight>.
  </p>

  <div style="display:flex;gap:1rem;justify-content:center;align-items:center;flex-wrap:wrap">
    <a href="#" style="font-weight:600;color:var(--mv-fg);text-decoration:none">
      <mv-text-highlight effect="underline" trigger="hover" duration="450">See pricing →</mv-text-highlight>
    </a>
    <button class="mv-button" data-variant="ghost" data-size="sm" id="th-replay">Replay</button>
  </div>
</div>
<script type="module">
  document.getElementById("th-replay")?.addEventListener("click", () => {
    document.querySelectorAll("#th-demo mv-text-highlight:not([trigger])").forEach((el) => el.replay());
  });
</script>

API

Attributes

NameTipoDefaultDescription
effectmarker | underline | circle | box | strikemarkerAnnotation style. SVG effects make the element inline-block (short phrases).
colorCSS colorvar(--mv-accent)Stroke / ink color (tokens accepted).
triggerview | load | hover | manualviewTrigger: entering the viewport (once), on load, on hover (of the parent link/button) or from script.
durationnumber800Draw duration (ms).
delaynumber0Delay before drawing (ms), to chain several annotations.

Methods

NameDescription
show()Draws the annotation.
hide()Erases the annotation (animated).
replay()Erases instantly, then redraws.

Events

NameDescription
mv-showWhen drawing starts.

CSS variables

NameDefaultDescription
--mv-text-highlight-colorvar(--mv-accent)Color (same as the color attribute).
--mv-text-highlight-markerMarker ink, if it should differ from the color (default: color at 28% / 45% in dark mode).
--mv-text-highlight-size78%Height of the marker stroke.
--mv-text-highlight-offset70%Vertical position of the marker.
--mv-text-highlight-stroke0.085emSVG stroke width.
--mv-text-highlight-easingvar(--mv-ease-in-out)Drawing easing curve.

Accessibility

The text is never modified; the SVG drawing is aria-hidden and ignores the pointer. To convey meaning (emphasis), wrap the content in <strong> or <mark>. Reduced motion: the annotation is shown right away, without drawing.

Esta página se tradujo con IA. Informar de un problema de traducción