Animate your Alpine components.

Overview

Animate your Alpine components 🚀

This package provides you with a simple helper to animate your ALpine.js components.

Installation

The recommended way to install the package is via NPM:

npm install @ralphjsmit/alpine-animate

Next, import and initialize the package in your js file:

import Alpine from 'alpinejs'
import Animate from '@ralphjsmit/alpine-animate'

Alpine.plugin(Animate)

window.Alpine = Alpine
Alpine.start()

You can also install the package via a CDN:

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

Usage

To prepare an animation on your component, you can add the x-animate and x-animate.reset attributes to it:

<div x-data="{ isAnimating: false }" x-cloak class="duration-[800ms]"
     x-on:notify.window="
    if (isAnimating) return;

    isAnimating = true;
    
    // Let's animate the notification. The animation should take 200ms.
    $animate(0.2);
    
    // The animation will take roughly 200 ms. When the notification is animating, we'll also 
    // start the process to hide it again.
    setTimeout(() => {
        // The 'reset animation' will take 0ms, so we'll just hide the notification immediately.
        $animateReset(0);
                
        isAnimating = false;
    }, 300);
  "
  <!-- When the component initializes, we'll call the $animateReset() magic helper to reset the state. We can use x-cloak to hide the component before this  initialization has happened. -->
  x-init="$animateReset(0)"
  x-animate="{
    top: '100px',
    right: '12px',
    opacity: '1.0'
  }"
  x-animate.reset="{
    top: '100px',
    right: '-200px',
    opacity: '0.0',
  }">

As you can see, you can call the $animate() helper to update the CSS properties to their new values. This is done inline, via the style attribute. When you want to revert the animation state, you can use the $animateReset() helper to reset the animation to it's initial state.

Calling the animation from a different component

An interesting and useful technique is to call the $animate() and $animateReset() helpers from another element. To do so, you can use the Alpine.evaluate() helper:

<div x-data>
    <button type="button"
    @click="Alpine.evaluate($el.nextElementSibling, '$animate()')">Click me!
</button>
<div class="bg-[red]" x-animate="{ background-color: 'orange' }"></div>
</div>

General

🐞 If you spot a bug, please submit a detailed issue and I'll try to fix it as soon as possible.

🙌 If you want to contribute, please submit a pull request. All PRs will be fully credited. If you're unsure whether I'd accept your idea, feel free to contact me!

🙋‍♂️ Ralph J. Smit

You might also like...

Multi-step wizard helpers for Alpine.js

Multi-step wizard helpers for Alpine.js

Alpine Wizard This package provides an Alpine directive (x-wizard) and a magic helper ($wizard) that allow you to quickly build multi-step wizards usi

Dec 23, 2022

📦 Alpine JS plugin to extend the functionality of the official $persist plugin

Alpine JS Persist Extended Alpine JS magic method $storage extends the official $persist plugin to help you work with local storage 📦 Example 👀 div

Dec 28, 2022

Alpine.js Language Features (Volar) extension for coc.nvim

[Experimental] coc-volar-alpinejs fork from vscode-alpine-language-features Alpine Language Features extension for coc.nvim Note @volar/alpine-languag

Oct 12, 2022

Little Alpine.js plugin to add a typewriter effect to any HTML element.

Little Alpine.js plugin to add a typewriter effect to any HTML element.

⌨️ Alpine Typewriter ⌨️ An Alpine.js plugin to add a typewriter effect to any HTML element. 🚀 Installation CDN Include the following script tag in

Dec 28, 2022

Easy to use and flexible router for Alpine.js

alpinejs-router Easy to use and flexible router for Alpine.js Installation npm npm install @shaun/alpinejs-router yarn yarn add @shaun/alpinejs-router

Dec 30, 2022

Animate on scroll library

❗ ❗ ❗ This is README for aos@next ❗ ❗ ❗ For last stable release (v2) go here 🚀 Demo 🌟 Codepen Examples Different built-in animations With anchor set

Jan 2, 2023

An easy way to animate SVG elements.

Walkway I loved the animations for the polygon ps4 review a few months back and decided to create a small library to re-create them (simple demo). It

Jan 2, 2023

animate.css as a Tailwind plugin

tailwind-animatecss Use animate.css as a Tailwind 3 plugin. Demo – https://dumptyd.github.io/tailwind-animatecss Table of contents Installation Usage

Dec 19, 2022

Quick and easy spring animation. Works with other animation libraries (gsap, animejs, framer motion, motion one, @okikio/animate, etc...) or the Web Animation API (WAAPI).

Quick and easy spring animation. Works with other animation libraries (gsap, animejs, framer motion, motion one, @okikio/animate, etc...)  or the Web Animation API (WAAPI).

spring-easing NPM | Github | Docs | Licence Quick and easy spring animations. Works with other animation libraries (gsap, animejs, @okikio/animate, mo

Dec 14, 2022
Releases(1.1.1)
Owner
Ralph J. Smit
Laravel Developer. Writer.
Ralph J. Smit
Add focal point alignment of images to your Alpine 3.x components with a custom directive.

Alpine Focal Add focal point alignment of images to your Alpine 3.x components with a custom directive. This package only supports Alpine v3.x. About

Michael Lefrancois 2 Oct 12, 2021
Adds a handy $parent magic property to your Alpine components.

✨ Help support the maintenance of this package by sponsoring me. Alpine $parent Access parent components using a handy $parent magic variable. This pa

Ryan Chandler 10 Aug 29, 2022
Straightforward interactive HTTP requests from within your Alpine.JS markup

Alpine Fetch Straightforward interactive HTTP requests from within your Alpine.JS markup. View the live demo here What does this do? Alpine.JS is a ru

null 29 Dec 21, 2022
The easiest way to animate your Next.js project. Scrollreveal.js helper package.

next-reveal The easiest way to animate your Next.js app Demo Introduction next-reveal makes it easy to add awesome scroll animations to your Next.js p

Zoltan Fodor 8 Nov 25, 2022
⏱ Simple Alpine.js plugin to display the human-readable distance between a date and now.

⏱ Alpine TimeAgo ⏱ An Alpine.js plugin to return the distance between a given date and now in words (like "3 months ago", "about 2 hours ago" or "in a

Marc Reichel 47 Dec 22, 2022
A clean integration between Cleave.js and Alpine. ✨

✨ Help support the maintenance of this package by sponsoring me. Alpine Mask This packages provide a custom x-mask directive and $mask magic variable,

Ryan Chandler 48 Dec 26, 2022
↕️ A little Alpine.js plugin to automatically resize a textarea to fit its content.

↕️ Alpine Autosize ↕️ A little Alpine.js plugin to automatically resize a textarea to fit its content. ?? Installation CDN Include the following <scri

Marc Reichel 42 Nov 5, 2022
A simple library for handling keyboard shortcuts with Alpine.js.

✨ Help support the maintenance of this package by sponsoring me. Alpine.js Mousetrap A simple library for handling keyboard shortcuts with Alpine.js.

Dan Harrin 102 Nov 14, 2022
IntelliSense for Alpine.js

IntelliSense for Alpine.js Features Provides syntax highlighting for Alpine.js directives along with autocomplete for all base directives and modifier

P Christopher Bowers 8 Nov 17, 2022
E-commerce website using Laravel, Tailwindcss and Alpine.js

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

TheCodeholic 15 Dec 12, 2022