Clicks and animation
Steps: <Click>, <After>, <Clicks>
Section titled “Steps: <Click>, <After>, <Clicks>”A click is a step within a slide. Pressing next walks a slide’s clicks before it moves on, and going back undoes each one.
<Click>Appears on the first click.</Click><After>Appears with the previous click, not a new one.</After>
<Clicks>
- One point- at a time,- in order
</Clicks><Click> takes:
| Prop | Meaning |
|---|---|
at |
when: at={3} (absolute), at="+2" (relative to the previous), at={[2, 5]} (shown from 2, hidden at 5) |
hide |
hide at that step instead of showing |
effect |
how it arrives (below) |
as |
the element it renders, div by default (as="span" inside a sentence, as="img" for a picture) |
<Clicks> wraps a list (or any children) and reveals one item per click; every={2} reveals two at a
time, depth reaches into nested lists, and effect applies to each item.
Effects: fade-in (the default), fade-out, fade-up, fade-down, fade-left, fade-right,
fade-in-then-out, fade-in-then-semi-out, semi-fade-out, current-visible, grow, shrink,
strike, highlight-red, highlight-green, highlight-blue, and the highlight-current-* variants
that highlight only while it is the current step. Any other name becomes the class effect-<name>
on top of the default fade, for your CSS to style; effect="custom" has no fade at all, so your CSS
alone decides how the step looks. A step also wears reveal.js’s classes (fragment, visible,
current-fragment), so CSS written for reveal works unchanged.
fragments: false in the headmatter turns steps off: every slide is drawn at its last step, and a
press goes straight to the next slide.
The slide’s total number of steps is counted from what its components ask for, so it follows any
change you make. When a component can’t announce its steps — your own, for instance — set clicks: N
in the slide’s frontmatter.
Code (line steps), maths ($$ {1|3|all}),
sketches, <Video> and <Mark> all take steps the same way, so a slide’s clicks line up whatever
they drive.
Content that depends on the step: <ClickCount>
Section titled “Content that depends on the step: <ClickCount>”<ClickCount> shows the slide’s current step, or anything that depends on it, without adding a step
of its own:
<Clicks>
- The Moon- The Sun- The coast
</Clicks>
<ClickCount>{(c, total) => `${c} of ${total} shown`}</ClickCount>
<ClickCount when={(c) => c >= 2}>Shown from the second click on.</ClickCount><ClickCount /> alone prints the current step, <ClickCount total /> the slide’s number of steps,
and offset={1} counts from 1.
In a component of your own, useClicks() returns the same numbers.
One thing at a time: <Switch>
Section titled “One thing at a time: <Switch>”<Switch> shows one child at a time and moves to the next on each click. The cases share one spot,
so nothing below them jumps when a longer one comes in.
<Switch transition="slide-up"><Case at={0}>What the slide opens with</Case><Case>After one click</Case><Case at="4-6">Steps 4 and 5</Case></Switch>- A
<Case>withoutattakes the step after the case before;at={0}is what the slide starts with;at="a-b"orat={[a, b]}shows it fromauntilb. The last case stays unless it has a range. aton the<Switch>itself moves its first step, as<Click at>does.transition:fade(the default),slide-up,slide-left,scaleornone.unmountleaves the hidden cases out of the page instead of hidden in it.
Hand-drawn marks: <Mark>
Section titled “Hand-drawn marks: <Mark>”<Mark> draws round a phrase on its click, stroke by stroke, the way a speaker would with a pen:
The answer is <Mark type="circle">forty-two</Mark>.
<Mark type="highlight" at={2} color="#fde047">Read this twice</Mark>
<Mark type="bracket" brackets="left right" color="#e11d48" at={3}>Both sides</Mark>| Prop | Meaning |
|---|---|
type |
underline (default), box, circle, highlight, strike-through, crossed-off, bracket |
at |
when, as <Click at>; default the next click, 0 always |
color |
any CSS colour; default the theme’s accent |
strokeWidth, padding, opacity |
line width (px), space round the text (px, or “top right bottom left”), 0–1 (a highlight defaults to 0.35) |
iterations, multiline |
strokes per line (default 2); one mark per wrapped line |
brackets |
for a bracket: left, right, top, bottom, or several |
duration, delay, animate |
drawing time and wait in ms; animate={false} draws it whole |
strike, line-through, cross and crossed are accepted as other names for the strike and cross
types. The wobble is seeded from the text, so the mark looks the same on every screen and in the PDF.
Things you place by hand
Section titled “Things you place by hand”<Drag pos="1400,120,380,_"> puts a block at stage coordinates you can move in kadal-deck dev, and
<DragArrow> draws an arrow whose ends you drag into place. See
Components.
Styles that know the direction
Section titled “Styles that know the direction”The deck root, the stage and the moving slides carry data-nav-direction="forward" or "backward"
(and --deck-nav-sign: 1 or -1), so a reveal can behave differently when you step back over it.
With Tailwind (the starter has it), forward: and backward: variants apply a class only in that
direction:
<Click className="transition forward:delay-300">Waits a moment going forward, never going back</Click>The starter declares them in src/styles.css; add these two lines to a deck that predates them:
@custom-variant forward (&:where([data-nav-direction="forward"] *));@custom-variant backward (&:where([data-nav-direction="backward"] *));Without Tailwind, plain classes cover the usual cases:
| Class | Effect |
|---|---|
deck-instant-back |
going back, it snaps away with no animation |
deck-instant-forward |
the same, going forward |
deck-delay-forward, deck-delay-backward |
waits --deck-forward-delay (or --deck-backward-delay, 300 ms) first |
deck-forward-only, deck-backward-only |
shown only while the deck moves that way |
In a component, useNavDirection() returns "forward" or "backward".
Transitions between slides
Section titled “Transitions between slides”transition: slide # none · fade · slide · convex · concave · zoom · view-transitiontransitionSpeed: fast # default · fast · slowbackgroundTransition: fadeSet them in the headmatter for the whole deck or on one slide. -in/-out suffixes give a slide
different entrance and exit transitions: transition: zoom-in fade-out. Under
prefers-reduced-motion the transitions are skipped.
Your own transitions
Section titled “Your own transitions”A transition is two CSS animations: one for the arriving slide, one for the slide leaving. Name the keyframes in the headmatter, then use the name like a built-in one:
---transition: fliptransitions: flip: in: flip-in out: flip-out back: { in: flip-in-back, out: flip-out-back } # optional; also up and down---Define the keyframes in your theme’s CSS, src/styles.css, or a <style global> on any slide:
@keyframes flip-in { from { transform: perspective(1600px) rotateY(-80deg); opacity: 0; }}@keyframes flip-out { to { transform: perspective(1600px) rotateY(80deg); opacity: 0; }}Plain CSS works too. The stage says what is happening on its own element, so you can set the two animations yourself:
.deck-stage[data-transition="flip"] { --deck-anim-in: flip-in; }.deck-stage[data-transition-out="flip"] { --deck-anim-out: flip-out; }.deck-stage[data-transition="flip"][data-direction="back"] { --deck-anim-in: flip-in-back; }data-direction is forward, back, up, down, or none for a jump. Either way the speeds and the
split form (flip-in fade-out) apply, reduced motion turns it into a cut, and print never animates.
A name nothing defines is a clean cut too, with one console warning. A theme or an addon can ship
transitions with registerTransition(name, { in, out }) from @kadal/deck; the deck’s own
transitions: wins for the same name.
Auto-animate
Section titled “Auto-animate”Put autoAnimate: true on consecutive slides and elements with the same data-id move between their
two positions: position, size, colour and radius interpolate.
---autoAnimate: true---
<div data-id="box" className="box small" />
---autoAnimate: true---
<div data-id="box" className="box big" />Deck-wide: autoAnimateEasing, autoAnimateDuration (seconds) and autoAnimateUnmatched; a slide
can set its own, for the animation into it. autoAnimateStyles lists the CSS properties that morph
(by default opacity, colour, background colour, padding, font size, line height, letter spacing,
borders and outlines). autoAnimateId keeps the animation between slides with the same id, and
autoAnimateRestart: true breaks the chain there.
While it runs, both slides carry data-auto-animate="pending" and then "running", and each
element taking part carries data-auto-animate-target (a number, or unmatched for one fading in),
for CSS to follow. To choose the pairs yourself, give deck.config.ts an autoAnimateMatcher(from, to) that returns [{ from, to }]. Auto-animate runs in the scroll view too.
Motion
Section titled “Motion”<Motion> animates an element through states keyed to clicks (it uses Motion, formerly Framer
Motion, under the hood):
<Motion initial={{ x: -80, opacity: 0 }} enter={{ x: 0, opacity: 1 }} clicks={{ "click-1": { x: 120 }, "click-2": { scale: 1.4 } }}> <div className="box" /></Motion>Auto-slide
Section titled “Auto-slide”autoSlide in the headmatter (milliseconds between steps) or on one slide. In the headmatter 0
leaves only the slides that set their own, and false turns it off outright, those included. A
step can wait its own time with <Click autoSlide={3000}> (or reveal.js’s data-autoslide), over
the slide’s. autoSlideMethod: right skips the vertical stacks (the default, next, walks every
step). With autoSlideStoppable (on by default) a press or any key the deck answers stops it, A
turns it back on, and the play view shows a pause/play control in the bottom-left corner, inside a
ring that fills as the slide’s time runs out. A deck that auto-slides still keeps the audience in
step, because the deck’s own advances carry a source and never end anyone’s follow.