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 🙏

© 2024 – Pkg Stats / Ryan Hefner

turbo-animate

v0.3.0

Published

Animate Turbo Drive's page transitions

Downloads

6

Readme

TurboAnimate

Silky-smooth CSS animations for Turbo Drive navigation events.

https://github.com/rzane/turbo-animate/assets/2731572/fc3c80e9-ad84-44c6-af70-cb2ae9c613e4

Installation

$ npm add turbo-animate

Usage

Step 1

Enable animations by calling the start function:

import "@hotwired/turbo";
import * as TurboAnimate from "turbo-animate";

TurboAnimate.start();

Step 2

Next, add data-turbo-animate to elements that you want to transition.

<main data-turbo-animate>
  This div should be animated.
</main>

Step 3

TurboAnimate will automatically add class names to your element to trigger animations. The example below will slide between screens.

Read the CSS documentation to learn more.

.turbo-advance-leave {
  animation: 200ms slide ease-out forwards;
  --translate-x: -100%;
}

.turbo-advance-enter {
  animation: 200ms slide ease-in forwards reverse;
  --translate-x: 100%;
}

.turbo-replace-leave,
.turbo-restore-leave {
  animation: 200ms slide ease-out forwards;
  --translate-x: 100%;
}

.turbo-replace-enter,
.turbo-restore-enter {
  animation: 200ms slide ease-in forwards reverse;
  --translate-x: -100%;
}

@keyframes slide {
  to {
    opacity: 0;
    transform: translate3d(var(--translate-x), 0, 0);
  }
}

CSS

Turbo has three visit types (also known as "actions"):

  • advance - The default action
  • replace - Triggered by a server redirect or data-turbo-action="replace"
  • restore - Triggered by pressing the browser back button

Each animation has two phases:

  • leave - Remove existing content from the screen.
  • enter - Add new content to the screen.

TurboAnimate will apply one of the following class names to each data-turbo-animate when a Turbo visit occurs:

  • turbo-advance-leave
  • turbo-advance-enter
  • turbo-replace-leave
  • turbo-replace-enter
  • turbo-restore-enter
  • turbo-restore-leave

You'll want to make sure to use animation-fill-mode: forwards (or, the forwards shorthand property). This property ensures that after the animation finishes, the element will retain the styles from the animation's last keyframe.

Custom actions

You've seen how to animate the advance, replace, and restore actions, but what if you want a different animation to run?

First, decide if you can solve this problem using only CSS:

#specific-element.turbo-advance-leave {}
#specific-element.turbo-advance-enter {}

If that doesn't scratch your itch, you can make your own action. Here's how:

<a href="/edit" data-turbo-animate-with="pop">Edit</a>

When that link is clicked, the following classes will be applied to your data-turbo-animate elements:

.turbo-pop-leave {}
.turbo-pop-enter {}

You can also initiate this animation using JavaScript:

import { visit } from "@hotwired/turbo";
import { setNextAction } from "turbo-animate";

setNextAction("pop");
visit("/edit");