DocsKeyboard & motion
Get started

Search Subtly documentation

Search by a task, helper name or framework.

Keyboard & motion

interruptibleMotion()

Let an animation reverse smoothly.

Try the example

Expand the details, then collapse them before the transition finishes. The visual reverses from its current position instead of jumping back or queuing animations.

Collapsed. Try toggling quickly.

Actual npm package · local demonstration

Add it to your project

  1. Copy the HTML. Place the markup inside the component where this behavior belongs. The preview’s visual classes are website styles; use your own design system.
  2. Connect the behavior. Copy the JavaScript tab and call its exported mount(element) after your component’s elements exist. Replace simulated delays and data operations with your own application code.
  3. Clean up. Call the returned cleanup when the component unmounts. It aborts the example’s listeners and releases the helper’s timers, observers or state.

API and lifecycle

Create an instance for an element, then call to(target, options) to animate selected style properties. It reads the current computed values so a new transition can begin from the current visual state. Defaults: 180 ms and ease-out.

Interface
to(target,{duration,easing}), destroy
Lifecycle
A new transition cancels the prior animation. destroy() cancels the active animation. The final target style is written to the element.

Accessibility and safety

Implementation notes

Initialize after the DOM is available. Keep native controls and keyboard interactions intact; release listeners and timers on unmount.

The helper skips animation when reduced motion is requested. Keep information and controls available without motion and avoid animating properties that disrupt reading.

What to check

Toggle repeatedly during the transition and check for jumps or queued motion. Enable reduced motion and verify the target state still appears.