Moving an element
A layer picks an element with src and changes it over time with place, look and content.
This page covers the layer kinds, src, life, delay, place, look, content for HTML and SVG, copies made with repeat and animate, and presets.
Every layer has an id and a kind.
An HTML layer moves one element, or each of several, from where the CSS put it.
place moves, turns and scales it, look fades, blurs and styles it, and content writes its text or its SVG attributes.
Each field takes a value, such as a number or a track.
The layer kinds
A layer's kind says what it draws.
Every layer has an id, unique in its list or comp, and one of these nine kinds.
htmlmoves an HTML element (this page).svgmoves an SVG element and sets its attributes (SVG content).textwrites an element's text, typed, scrambled, split into letters or words, or as captions (Text layers).lottieplays a Lottie animation in its element (below).compplaces a group of layers, once or once for each row of data (Comps and copies).camera,path,solidandnullwork in 3D (Solids, cameras and paths).
Here one layer finds three cards. Each card rises, sharpens and fades in, a quarter of a second after the one before.
<div data-composition-id="main" data-start="0" data-duration="4"
data-width="1280" data-height="720" data-fps="30">
<div class="row" data-component="cards" data-start="0" data-duration="4">
<div class="card">Sow</div>
<div class="card">Grow</div>
<div class="card">Bloom</div>
</div>
</div>
wildflower.kinetic.layers.scene('cards', {
layers: [
{
id: 'cards', kind: 'html', src: '.card',
delay: { stagger: { each: 0.25 } },
place: { translate: [0, { at: [0, 0.9], to: [80, 0], ease: 'power3.out' }] },
look: {
opacity: { at: [0, 0.5], to: [0, 1] },
blur: { at: [0, 0.7], to: [10, 0] },
},
},
],
});
html, body { margin: 0; }
[data-composition-id] {
position: relative;
overflow: hidden;
background: #0b0f1a;
color: #fff;
font-family: system-ui, sans-serif;
}
[data-composition-id]:not([data-kinetic-ready]) { visibility: hidden; }
.row {
position: absolute;
inset: 0;
display: flex;
align-items: center;
justify-content: center;
gap: 40px;
}
.card {
width: 300px;
height: 360px;
border-radius: 18px;
background: #1d2340;
display: flex;
align-items: center;
justify-content: center;
font-size: 56px;
font-weight: 700;
}
src: '.card'finds all three cards, and the layer draws each one.delaystarts each card's time later, and{ stagger: { each: 0.25 } }gives the first card 0, the second 0.25 and the third 0.5 seconds.- The tracks then play the same way on each card, from its own start.
src
src is a CSS selector for the element the layer draws.
html, svg, text and lottie layers need one, and a layer of those kinds without it is KN-162.
{ id: 'title', kind: 'html', src: 'h1', look: { opacity: { at: [0, 0.5], to: [0, 1] } } }
The layer fades in the clip's h1.
The selector is looked for in the scene's clip first, and in the whole composition when the clip has no match, so a layer can move an element that sits beside its clip.
A selector that finds nothing is KN-168.
{ id: 'dots', kind: 'html', src: '.dot', delay: { stagger: { each: 0.5 } }, look: { opacity: { at: [0, 1], to: [0, 1] } } }
A selector that finds several elements draws each one with the same tracks.
Each element has its own i of n, its place among them counting from 0, which a stagger or a value can read.
Here each dot fades in half a second after the one before.
{ id: 'pair', kind: 'html', src: ['#one', '#two'], look: { opacity: 'fadeIn' } }
A list of selectors draws every element each one finds, so #one and #two both take the shared fade fadeIn.
{ id: 'ground', kind: 'html', src: ':scope', look: { style: { background: { at: [0, 3], to: ['#0b0f1a', '#181030'] } } } }
':scope' is the clip's own element, so this layer turns the clip's background from near black to deep purple over 3 seconds.
Inside a repeated comp, ':scope' is that copy's own element (Comps and copies).
life
{ id: 'flash', kind: 'html', src: '.flash', life: [1, 2.5] }
life: [start, end) shows the layer from start until end, and sets display: none on its element outside that span.
The flash appears at 1 second and is gone at 2.5 seconds.
Every kind takes life, and a layer without it shows for the whole clip.
{ id: 'outro', kind: 'html', src: '.outro', life: ['intro + 0.5', 'end'] }
Each end takes any value, such as a name or a sum.
Here the outro shows from half a second after the clip intro ends to the end of the scene's clip.
delay
{ id: 'tagline', kind: 'html', src: '.tag', delay: 1.5, look: { opacity: { at: [0, 0.5], to: [0, 1] } } }
delay starts the layer's time that much later, so the tracks play as if the clip started 1.5 seconds later.
The tagline fades in from 1.5 to 2 seconds.
html, svg and text layers take it.
The delay is worked out for each element, so { stagger: { each: 0.08 } } gives each element its own start, as in the cards above.
stagger() has its other options, such as from: 'center' and total.
place
place moves, turns and scales the element from where the CSS put it.
Layers and keyframes shows each of these on a heading.
place: { translate: [{ at: [0, 1], to: [-200, 0] }, 0] }
translate is [x, y] in px, so this slides the element in from 200 px to the left.
place: { rotate: { at: [0, 1], to: [-90, 0] }, scale: { at: [0, 1], to: [0.5, 1] } }
rotate is in degrees and scale is one number, or [x, y] for each axis.
The element turns a quarter turn back into place as it grows to full size.
The parts are combined into one CSS transform, translate first, then rotate, then scale.
place: { shift: ['-50%', { at: [0, 0.8], to: [100, 0], unit: '%' }] }
shift moves the element by a share of its own size, [a, b], each a CSS length such as '-50%' or a track with a unit.
Here the element sits half its width to the left and rises from one whole height below.
place: { translate: [0, 0, -200], rotate: [0, { at: [0, 1.2], to: [90, 0] }, 0], perspective: 800 }
A translate of [x, y, z] or a rotate of [x, y, z] degrees turns the element in 3D.
perspective, in px, sets the depth of the element's own turn.
This card swings in about its upright axis, 200 px back.
{ id: 'blade', kind: 'svg', src: '.blade', place: { rotate: { rate: 90 }, pivot: [100, 100] } }
On an SVG element, rotate is written as the element's transform attribute, turning about pivot, a point in the SVG's own units ([0, 0] when left out).
The blade turns 90 degrees a second about the point (100, 100).
place.position and place.pivot in the stage's units place a solid or a layer in the 3D world (Solids, cameras and paths).
look
look holds how the element looks.
look: { opacity: { at: [0, 0.5, 3.5, 4], to: [0, 1, 1, 0] } }
opacity fades the element in over half a second and out over the last half second of a 4-second clip.
look: { blur: { at: [0, 0.6], to: [12, 0] } }
blur is a CSS filter: blur() in px, so the element comes into focus over 0.6 seconds.
At 0 the filter is none.
look: { style: { width: { at: [0, 2], to: [0, 480], unit: 'px' }, color: { at: [0, 2], to: ['#9d7bff', '#ffffff'] } } }
style sets any CSS property by name, here a bar that grows to 480 px wide while its text turns from purple to white.
A number track takes a unit, which is written after the number.
The browser ignores a length with no unit, and development builds warn once about a number or a number track that has none (KN-122).
A color track blends between the colors (Layers and keyframes lists the color forms).
A custom property such as '--glow' works too.
look: { color: 'accent' }
look.color sets the element's text color, and a swatch or role name there, or anywhere in look.style, is that color (Roles and swatches).
When a layer gives both look.color and look.style.color, look.style.color wins.
// <path class="line" d="..." pathLength="1" stroke-dasharray="1 1" stroke-dashoffset="1"/>
{ id: 'line', kind: 'svg', src: '.line', look: { trim: { end: { at: [0, 1.5], to: [0, 1] } } } }
trim.end draws an SVG path on from its start, from nothing at 0 to the whole path at 1.
The path needs pathLength="1" and stroke-dasharray="1 1", and the layer sets its stroke-dashoffset.
While end is 0 the path is hidden, so not even its line cap shows.
presetplays one of the scene'spresets(Presets).effect,shade,backdrop,draw,boil,transition,smear,trailsandrepeatrun Kinetic's calls on the element (Layer calls).wordsstyles a caption's words (Text layers).
content
HTML content
{ id: 'count', kind: 'html', src: '.count', content: { text: { floor: { rate: 10 } } } }
An HTML layer's content takes text, which writes the element's text.
{ rate: 10 } grows by 10 a second and floor rounds it down, so the element counts up 0, 1, 2 and so on, ten numbers a second.
A string in content.text is shown as written, so content: { text: 'end' } shows the word "end".
To show a named value, such as a constant, put the name in a one-item list, whose item is read as a value.
constants: { total: 42 },
layers: [{ id: 'count', kind: 'html', src: '.count', content: { text: ['total'] } }] // shows 42
SVG content
{ id: 'ball', kind: 'svg', src: '.ball', content: { r: { at: [0, 2], to: [10, 80] }, fill: { keys: [[0, '#ffffff'], [2, 'sky']] } } }
An SVG layer's content sets any attribute by name, such as d, cx, fill or 'stroke-width'.
The circle's radius grows from 10 to 80 over 2 seconds as its fill turns from white to the swatch sky.
- Numbers are written to one decimal place, and
opacityto three. - A color can be a swatch's or a role's name, which is looked up (Values).
textwrites the element's text, as on an HTML layer.- A
dtrack can morph one path into another (Values), and other layers read the drawn path as'id.d'.
This dial draws its arc, turns its needle and counts its reading together.
<div data-composition-id="main" data-start="0" data-duration="4"
data-width="1280" data-height="720" data-fps="30">
<div class="dial" data-component="dial" data-start="0" data-duration="4">
<svg viewBox="0 0 400 260" width="640" height="416">
<path class="track" d="M 40 220 A 160 160 0 0 1 360 220" />
<path class="arc" d="M 40 220 A 160 160 0 0 1 360 220"
pathLength="1" stroke-dasharray="1 1" stroke-dashoffset="1" />
<line class="needle" x1="200" y1="220" x2="200" y2="80" />
<circle class="hub" cx="200" cy="220" r="10" />
</svg>
<b class="reading"></b>
</div>
</div>
wildflower.kinetic.layers.scene('dial', {
shared: { level: { at: [0.3, 2.5], to: [0, 0.8], ease: 'power2.inOut' } },
layers: [
{ id: 'arc', kind: 'svg', src: '.arc', look: { trim: { end: 'level' } } },
{ id: 'needle', kind: 'svg', src: '.needle', place: { rotate: { add: [-90, { multiply: ['level', 180] }] }, pivot: [200, 220] } },
{ id: 'reading', kind: 'html', src: '.reading', content: { text: { floor: { multiply: ['level', 100] } } } },
],
});
html, body { margin: 0; }
[data-composition-id] {
position: relative;
overflow: hidden;
background: #0b0f1a;
color: #fff;
font-family: system-ui, sans-serif;
}
[data-composition-id]:not([data-kinetic-ready]) { visibility: hidden; }
.dial {
position: absolute;
inset: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.track, .arc { fill: none; stroke-width: 22; stroke-linecap: round; }
.track { stroke: #1d2340; }
.arc { stroke: #9d7bff; }
.needle { stroke: #fff; stroke-width: 6; stroke-linecap: round; }
.hub { fill: #fff; }
.reading { margin-top: -20px; font-size: 72px; font-variant-numeric: tabular-nums; }
levelis asharedvalue, a track from 0 to 0.8 that the three layers read by its name.- The arc's
trim.endis the level, so 80 percent of the arc is drawn at the end. - The needle starts pointing left, at -90 degrees, and turns 180 degrees for a full level, about the hub at (200, 220).
- The reading is the level times 100, rounded down, so it counts to 80.
Lottie content
{ id: 'logo', kind: 'lottie', src: '.logo', content: { path: 'logo.json', start: 0.5, rate: 1, loop: false } }
A lottie layer plays a Lottie animation in its element with Kinetic's lottie(), so it follows the clock.
content takes path (the animation's JSON file), renderer ('svg' by default), start (when it starts, in the layer's time), rate and loop (play again from the start, or hold the last frame).
Load lottie-web on the page first, or the layer is KN-100.
Copies with repeat and animate
An HTML layer with repeat makes copies of the <template> inside its element, and animate gives each copy its own tracks.
A copy is one clone of the template.
<div data-composition-id="main" data-start="0" data-duration="5"
data-width="1280" data-height="720" data-fps="30">
<div class="pond" data-component="pond" data-start="0" data-duration="5">
<div class="bubbles">
<template><i class="bubble"></i></template>
</div>
</div>
</div>
wildflower.kinetic.layers.scene('pond', {
layers: [
{
id: 'bubbles', kind: 'html', src: '.bubbles',
repeat: { every: 0.4, life: 2.4 },
animate: {
place: {
translate: [{ wiggle: { frequency: 1.2, amplitude: 60, seed: 'i' } }, { at: [0, 2.4], to: [0, -560] }],
scale: { at: [0, 2.4], to: [0.4, 1.3] },
},
look: { opacity: { at: [0, 0.3, 1.8, 2.4], to: [0, 1, 1, 0] } },
},
},
],
});
html, body { margin: 0; }
[data-composition-id] {
position: relative;
overflow: hidden;
background: #0b1a1f;
}
[data-composition-id]:not([data-kinetic-ready]) { visibility: hidden; }
.pond { position: absolute; inset: 0; }
.bubbles { position: absolute; left: 50%; bottom: 60px; }
.bubble {
position: absolute;
left: -24px;
top: -24px;
width: 48px;
height: 48px;
border-radius: 50%;
border: 4px solid #7fd6c8;
}
repeat: { every: 0.4, life: 2.4 }adds a copy every 0.4 seconds and shows it while its age is under 2.4 seconds. Copies added before frame 0 are included, so the stream is already running at the first frame.animateplays on each copy in its own time, its age, so every bubble rises 560 px and grows as it ages.- A copy added this way reads its index as
iand its age asage. Hereseed: 'i'gives each bubble its own sidewayswiggle. - Copies stand in the order they were added, the newest last.
{ id: 'steps', kind: 'html', src: '.steps', repeat: { count: 4 }, animate: { place: { translate: ['40i', 0] } } }
repeat: { count: 4 } makes four copies on the layer's own time, each reading its i of n.
'40i' is 40 times i, so the copies stand 40 px apart.
The count can be any value, such as a link to a knob.
animate takes place (translate, rotate, scale) and look (opacity, blur, color, class, style).
look.class adds a class to the copy while it has a value, and look.color sets the copy's text color.
animateon an HTML layer needsrepeat, andrepeatis either{ every, life }or{ count }, or the layer is KN-162.- An element with no
<template>inside it is KN-168. - A text layer's
animatemoves its letters or words instead (Text layers), and akind: 'comp'layer'srepeatplaces a comp once for each row (Comps and copies).
Presets
{
presets: {
rise: {
opacity: { at: [0, 0.25], to: [0, 1] },
y: { at: [0, 0.45], to: [18, 0], ease: 'power3.out' },
scale: { at: [0, 0.45], to: [0.92, 1], ease: 'power3.out' },
},
},
layers: [
{ id: 'tagline', kind: 'html', src: ['#tag1', '#tag2', '#tag3'], stagger: { starts: [1, 1.3, 1.5] }, look: { preset: 'rise' } },
],
}
A preset is an animation that several layers play by its name.
The scene's presets holds each one as three tracks, opacity, y (px) and scale, and look: { preset: 'rise' } plays it from the layer's own start.
Here each of the three words rises 18 px into place as it fades in.
stagger: { starts: [...] }on an HTML layer gives each element its own start, one time for each element itssrcfinds, so the words arrive at 1, 1.3 and 1.5 seconds.- A track the preset leaves out stays at rest: opacity 1, no rise, and scale 1.
A number holds still too, so
scale: 1leaves the size alone. - A preset writes the element's
opacityandtransform. A layer that plays a preset draws nothing else, so its ownplace,look.opacity,blur,styleandcontentare left out.
Lookup: a layer's keys
The keys each kind takes, besides id, kind and life, which every layer takes.
A key a kind does not take is KN-162.
| Key | Kinds | Meaning |
|---|---|---|
src | html, svg, text, lottie | A selector for the element the layer draws, searched for in the scene's clip first and then in the whole composition, or a list of selectors.
A selector that matches several elements draws each one, with its own i of n.
':scope' is the clip itself, or, inside a repeated copy, that copy's own element. |
life | all | [start, end).
The layer shows from start until end and has display: none outside that span. |
delay | html, svg, text | Starts the layer's time that much later, worked out per element, such as { stagger: { each: 0.08 } }. |
stagger | html | { starts: [...] }, each element's start for its look.preset. |
place | all but comp, camera, and path | translate ([x, y] px, or [x, y, z]), rotate (degrees, or [x, y, z]), scale (a number, or [x, y]), shift ([a, b], a share of the element's own size: CSS lengths such as '-50%', or tracks with a unit), perspective (px, for the element's own 3D turn), and position and pivot for solids and the 3D world.
On an SVG layer, rotate turns about pivot. |
look | all but null, comp, and camera | opacity, blur (px), style ({ cssProperty: value }; a value with unit: 'px' is written with that unit), trim (an SVG path's end), preset, and the layer calls. |
content | solid, html, svg, path, text, lottie | html: text.
solid and path: Solids, cameras and paths.
svg: any attribute by name (d, cx, fill, 'stroke-width', ...), with numbers written to one decimal place.
text: Text layers.
lottie: path, renderer, start, rate, loop. |
repeat | html | Copies of the element's <template>.
{ count } makes that many copies on the layer's time, each reading its i of n.
{ every, life } adds a copy every every seconds and shows it while its age is under life, including copies added before frame 0. |
animate | html with repeat, text | Each copy's or part's tracks, in its own time: place: { translate, rotate, scale } and look: { opacity, blur, color, class, style }. |
parent | all but camera | The layer it moves with (Solids, cameras and paths). |
band | solid, html | Its place in the scene's stated draw order (Solids, cameras and paths). |
size, group | html | The 3D world (Solids, cameras and paths). |
Next
Values covers every form a value takes, from a plain number to links, functions and the music.