npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@braedencrankd/alpine-motion

v0.3.8

Published

An AlpineJS plugin for using the MotionOne API with Alpine Directives

Downloads

114

Readme

alpine-motion

alpine_motion_example

View the demo.

DISCLAIMER: This package is still in active development and is not ready for production use. I'm open to any suggestions on improving this package.

Resources

Table of Contents

Installation

With a CDN

<script
  defer
  src="https://unpkg.com/@braedencrankd/alpine-motion@latest/dist/alpineMotion.min.js"
></script>

<script defer src="https://unpkg.com/[email protected]/dist/cdn.min.js"></script>

With NPM

To install the "alpine-motion" package, you can use npm, pnpm or yarn. Run the following command in your project directory:

npm install @braedencrankd/alpine-motion
# or
yarn add @braedencrankd/alpine-motion
# or
pnpm install @braedencrankd/alpine-motion

Setup

Import the alpine-motion plugin in your project entry point.

import alpineMotion from "alpine-motion";
Alpine.plugin(alpineMotion);

Usage

Using the x-motion Directive

Define the x-motion directive on an element to create a motion animation. The following example will create a motion animation that will rotate the element 90 degrees over 1.5 seconds.

Note: make sure to add the x-init or x-data directive to the container element to ensure the x-motion is initialized when Alpine is loaded.

<div x-init class="container mx-auto mt-10">
  <div class="flex flex-wrap gap-2 mb-10">
    <!-- Playing a named animation -->
    <button
      class="px-6 py-1.5 rounded bg-gray-200"
      @click="$motion('box-animation-1').play()"
    >
      Play
    </button>
    <!-- Plauing another named animation on the same element -->
    <button
      class="px-6 py-1.5 rounded bg-gray-200"
      @click="$motion('box-animation-2').play()"
    >
      Reverse
    </button>
  </div>
  <!-- Defining two different animations on the same element -->
  <div
    x-motion="{
      'box-animation-1': [ { rotate: 90 }, { duration: 1 } ],
      'box-animation-2': [ { rotate: -90 }, { duration: 1 } ],
    }"
    class="w-24 h-24 bg-indigo-500 rounded-lg"
  ></div>
</div>

Nameless Animations

The simplist way to declare animations is by creating nameless animation using the x-motion directive. Nameless animations are run when the animated element is visible in the viewport.

<div x-motion="{ rotate: 90 }, { duration: 1.5 }">...</div>

Named animation

The alternative method of declaring animations is by creating named animations. This is where you can delcare one or more animations in x-motion directive expressions where the name is the key for each animation.

<div
  id="test-1"
  x-motion="{
  'animation-one': [ {x: 100} , { duration: 0.5 } ],
}"
  class="mt-10 w-24 h-24 bg-teal-400 rounded-lg"
></div>

The benefit of this syntax is that these animations get put in an Alpine Store where you can run the animations at any point.

$motion magic ✨

The $motion alpine magic is used for getting and executing stored animations.

<button
  class="px-4 py-2 font-bold text-white bg-blue-500 rounded hover:bg-blue-700"
  @click="$motion('box-animation-1').play()"
>
  Play
</button>

Reactive Animations 🪄

Here we are updating the the currentRotationPos variable when the buttons are clicked. Because this value is being used in the animation, the animation will run with the updated value.

<div x-data="{currentRotationPos: 0}">
  <div class="flex flex-wrap gap-2 mb-6">
    <button class="px-6 py-1.5 rounded" @click="currentRotationPos += 90;">
      +90
    </button>
    <button class="px-6 py-1.5 rounded" @click="currentRotationPos -= 90;">
      -90
    </button>
  </div>

  <div
    x-motion="{ rotate: currentRotationPos }, { duration: 1.5 }"
    class="w-24 h-24 bg-indigo-500 rounded-lg"
  ></div>
</div>

in-view modifier

The in-view modifier is used to trigger animations when the element is in the viewport.

<div
  x-motion.in-view="{
  'in-view-animation': [ { rotate: 90 }, { duration: 1 } ],
}"
>
  ...
</div>

Scroll Triggered Animations 📜

Basic scroll triggered animations are created by adding the scroll modifier to the x-motion directive.

<div x-motion.scroll="{ rotate: 90 }">...</div>

If you need to localize where the scroll starts and stops you can define the scrollTarget and scrollContainer options.

<div
  x-motion.scroll="{ rotate: 90 }, { scrollTarget: '#scroll-container', scrollContainer: '#scroll-container' }"
>
  ...
</div>

Scroll Triggered Animations with Alpine Magic 🪄

You can also use Alpine Magic to trigger scroll triggered animations.

<div x-init="$nextTick(() => $scroll('scroll-animation'))">
  <div
    x-motion="{
      'scroll-animation': [ { rotate: 90 } ],
    }"
  >
    ...
  </div>
</div>