Auto Writer
A runnable demo of vUX-autoWriter.js. See the Auto Writer guide for the full API.
Live example
Runs the module from this site, with every control on the page. Open it in its own tab for the full layout.
The page
| Section | Shows |
|---|---|
| Hero | a headline typed on load, and a subject line that rewrites itself on a loop |
| Playground | live editing of the script and every config property, against one writeText() call |
| Directives | |, *n* and ~n~, each in its own isolated demo |
| One call, many elements | a NodeList and an array of strings typed in sequence |
| Bad input | the five ways writeText() and deleteText() reject arguments |
What it demonstrates
- The directive syntax carries the choreography. The "Rewrite" preset types a sentence, pauses, backspaces fourteen characters and finishes differently: as one string, with no callback chain. Nothing on the page re-renders; characters are appended as text nodes.
- No
initialize(). Unlike the trigger-driven vUX components,AutoWriteris driven by method calls, so there is nothing to activate. Every writer here isnew AutoWriter()and then straight towriteText(). - Randomised per-character timing. The two speed sliders are the min and max of the range a fresh delay is drawn from on every keystroke; drag them together to see how mechanical equal bounds look.
- Cursor states. The caret is steady while typing, blinks only during a
~n~pause, and hides when the run ends. Watch the hero line: it holds a blinking caret because its string ends in~1200~. stop()cancels mid-run and leaves the text where it stood, without firing the callback.deleteText()targets the same element you typed into. The button erases five units from the playground stage: the caret is not one of them.- Sequencing across elements. "Run sequence" hands one
NodeListand one array to a single call; each card starts when the last finishes and the callback fires once, at the end. - Directives are validated up front. The buttons in the last section throw synchronously, from the
writeText()/deleteText()call itself, so a typo surfaces in your owntry/catchrather than inside a timer seconds later.
Two things worth copying
Give the caret a height. The library styles .vAutoWriterBlinker with only a left border, which leaves its size at the mercy of the surrounding line. This page adds:
css
.vAutoWriterBlinker{ display:inline-block; height:1.02em; vertical-align:text-bottom; margin-left:3px; }Reserve the line. An element that starts empty and fills with text will shift the page as it grows. Every target here carries a min-height of roughly one line so the layout is settled before the first character lands.