On this page

Getting started

Install solid-motion in a Solid 2 app and animate your first element.

sh
npm install @risinghq/solid-motion

Set up the build

Vite needs the Solid plugin, which a Solid app already has:

ts
// vite.config.ts
import solid from "@solidjs/vite-plugin";
import { defineConfig } from "vite";

export default defineConfig({ plugins: [solid()] });

With another bundler, compile Solid JSX inside node_modules too, because the package ships TSX.

For TypeScript, set "jsx": "preserve" and "jsxImportSource": "@solidjs/web" in tsconfig.json.

Animate something

tsx
import { motion } from "@risinghq/solid-motion";
import { render } from "@solidjs/web";
import { createSignal } from "solid-js";

function App() {
  const [open, setOpen] = createSignal(true);

  return (
    <>
      <button onClick={() => setOpen((value) => !value)}>Toggle</button>
      <motion.div
        initial={{ opacity: 0, y: 20 }}
        animate={{ opacity: open() ? 1 : 0.2, y: 0 }}
        transition={{ duration: 0.2 }}
      >
        Fades and slides in on mount
      </motion.div>
    </>
  );
}

render(() => <App />, document.getElementById("root")!);

The element starts at initial and animates to animate on mount. It animates again each time a signal read inside animate changes.

Animating elements covers the rest of the props. If you know motion/react, start with what differs in the code.