axi0motion

Dodge

Children slip away from the pointer, then glide home when it rests.

  • enhancer
  • pointer
  • playful
  • spring
  • since 0.2

Background Studio: tune it below, then copy the code

Your system asks for reduced motion: the demo shows its final state and nothing moves.

Live demo

Dodge example

Catchmeifyoucan

Controls

90 px
1
900 ms

Code

It follows the controls above: change an option and the code changes with it.

<link rel="stylesheet" href="/axi0/motion/motion.css?v=6">
<script src="/axi0/motion/motion.js?v=10" defer></script>

<div class="m-dodge" data-motion="dodge"><span>Catch</span><span>me</span><span>if</span><span>you</span><span>can</span></div>

The wrappers: Dodge.tsx (React, TypeScript) and Dodge.vue (Vue). Both render the same attributes as the HTML; the loader does the rest.

Options

AttributeDefaultWhat it does
data-motion-radius90how close, in pixels beyond a child's own size, the pointer may come
data-motion-strength1how far a child slips (1 keeps it just out of reach)
data-motion-rest900milliseconds of a still pointer before the children glide home

Accessibility

Children move with transforms only, so the layout never changes, and a child that holds keyboard focus never moves away from it. On touch, a tap pushes the children near it, and they come back on their own. Reduced motion: nothing moves.

Size

dodge.js is 1.3 KB gzip. A page loads the loader (2.7 KB) and core.js (1.4 KB) once, whatever it uses.