createAnimate animates elements that you do not render with motion.*: nodes
that a chart library creates, or elements that you pick by selector.
import { createAnimate } from "@totallynotdavid/solid-motion";
function Toolbar() {
const [scope, animate] = createAnimate();
return (
<div ref={scope}>
<button
onClick={() =>
animate(".dot", {
scale: [1, 1.5, 1],
transition: { duration: 0.4 },
})
}
>
Pulse
</button>
<span class="dot" />
</div>
);
}createAnimate() returns [scope, animate].
scopeis a ref. Put it on the root element.scope.currentis that element, orundefinedbefore it mounts.animate(target, definition)animates the target and returns the playback controls.
target is an element, an array of elements, or a CSS selector. A selector is
searched inside scope.current. Before the scope mounts, a selector matches
nothing.
definition is a target as in animate={...}: values, an optional transition
and an optional transitionEnd.
The return value of animate has stop(), pause(), play(), complete(),
cancel(), time, speed, duration, state and finished. It is also
awaitable.
await animate(".dot", { opacity: 0 });finished also settles when you call stop(). A call that you make before the
first frame runs, such as pause(), is applied once the animation starts.
Pass a list of [target, definition] steps to run them one after another. Each
step starts when the one before it ends.
await animate([
[".title", { opacity: 1 }],
[".body", { opacity: 1 }],
]);- Animations stop when the owner of
createAnimateis cleaned up. MotionConfigapplies: itstransitionis the default,skipAnimationsjumps to the target, andreducedMotionmakes movement jump.- If a
motion.*element andanimatetarget the same property of one element, the later call takes over, and the earlier one settles.