Start
Getting started
Install Kinesis, mark a scope, add a property.
Install
npm install @amineyarman/kinesis
import { initKinesis } from "@amineyarman/kinesis"
initKinesis()
Without a build step, this script tag starts Kinesis and exposes window.Kinesis:
<script src="https://cdn.jsdelivr.net/npm/@amineyarman/kinesis/dist/kinesis.global.js"></script>
Importing @amineyarman/kinesis/auto from a CDN also starts it.
Kinesis supports Chrome and Edge 111+, Safari 16.4+, and Firefox 128+. Older browsers get less motion or none.
Mark a scope
data-kinesis marks a scope. Kinesis searches it for animated elements and measures the pointer against it.
<section class="hero" data-kinesis>
<div class="hero__glow"></div>
<h1 class="hero__title">Hello</h1>
</section>
Put it on <body> to cover the whole page.
Add a property
.hero__glow {
--k-parallax: 40px;
}
.hero__title {
--k-parallax: -12px;
--k-motion: soft;
}
The glow drifts away from the pointer and the title drifts toward it. Both settle when the pointer leaves.
Somewhere quiet
Add a reaction
--k-when picks a trigger. Outputs set what changes.
.button {
--k-when: press;
--k-scale: 0.94;
}
.feature {
--k-when: view once;
--k-opacity: 0 1;
--k-y: 24px 0;
}
The button shrinks while pressed, by mouse, touch, or keyboard. Each feature fades in the first time it scrolls into view. See Reactions.
Frameworks
Vue has a plugin with a v-kinesis directive. React, Svelte, and others use initKinesis() with CSS, or kinesis() in an effect. See Vue and other frameworks.
If nothing moves
initKinesis()must run in the browser. In server-rendered apps, call it on the client.- CSS properties only work inside a
[data-kinesis]container.kinesis()in JavaScript works anywhere. - Inline elements can't be transformed. Use
display: inline-blockorblock. - A
transitionon the animated properties, usuallytransition: all, smooths every update twice and makes motion lag. Limit it to other properties. - With
prefers-reduced-motion: reduce, pointer effects stay at rest. See Accessibility.
initKinesis({ debug: true }) reports these problems in the console.