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

tev-turbo-animate

v3.2.3

Published

Rich & adaptive animations for apps using Turbolinks™

Downloads

4

Readme

Turbo Animate

NPM Version Travis

A dead simple & powerful way of adding rich & adaptive animations to your app which is already using Turbo™.

Extensions


Table of Contents


Usage

Functions

// Shows the initialized element
TurboAnimate.appear();

// Hides the initialized element
TurboAnimate.disappear();

Options

There are a number of ways in which you can adopt Turbo Animate to your needs:

Animations:

The vital part is choosing an animation to play. Turbo Animate utilizes Animate.css to power them. These are the animations which are currently accessible:

There are three ways in which you can specify the animation you want to use. To choose a globally used animation pass an option when initializing Turbo Animate:

TurboAnimate.init({animation: 'fadeinright'});

Note: The option falls back to fadein.

Note: As a global choice you would only want to use appearing animations, as they will get fade out automatically when the current view disappears.

For alternate approaches take a look at inline animations and animations overriding animations.

Options:

  • duration CSS value for animation-duration. Accepts a string. Defaults to 0.3s.

  • delay Milliseconds after which animation starts. Accepts an integer or false. Defaults to false.

  • reversedDisappearing Whether or not a reversed animation should be used when disappearing. Accepts a boolean. Defaults to false.

  • breakpoints An array of breakpoint objects to specify breakpoints used for Per Device-Type animations. Accepts an array. Defaults to: [{ name: 'mobile', width: 500 },{ name: 'tablet', width: 1024 },{ name: 'desktop', width: 1440 }]

  • customListeners Restore the behavior of versions < 2 to set custom listeners to run appear() and disappear() functions. Accepts a boolean. Defaults to false.

Example:

TurboAnimate.init({animation: 'fadeinright', duration: '1s', delay: 1000});

Inline animations

With Turbo Animate you are able to set animations based on the links, who got clicked:

<a href="" data-turbo-animate-animation="fadeout" data-turbo-animate-duration="0.3s" data-turbo-animate-delay="250">I am a link!</a>

Attributes:

  • data-turbo-animate-animation Animation to be applied when disappearing after a hyperlink got clicked. Accepts a string. Set it to 'false' to disable Turbo Animate on this specific link.

  • data-turbo-animate-appear Animation to be applied when appearing on the next view after a hyperlink got clicked. Accepts a string.

  • data-turbo-animate-duration CSS value for animation-duration. Accepts a string.

  • data-turbo-animate-delay Milliseconds after which animation starts. Accepts an integer or false.

Per Device-Type

In addition you can specify animations specifically for certain screen sizes, just pass a hash:

TurboAnimate.init({animation: {'mobile': 'fadeinup', 'tablet': 'fadeindown', 'desktop': 'fadein'}});

Note: You can customize the breakpoints through the options.

Overriding animations

A lot of times with frameworks like Ruby on Rails you want to be able to specify animations from within your controllers and views without nasty javascript nesting.

With Turbo Animate you can just add a data attribute to your initialized element, naming the animation you want to use. It will override the global default:

<body data-turbo-animate-animation="fadeinup"></body>

Persistent elements

A lot of times you want to persist certain elements throughout requests, for example a navigation bar or other parts of your layout that is being shared between views. Turbo Animate makes it dead simple to declare persistent elements in your view:

<body data-turbo-animate-animation="fadein">
  <h1 data-turbo-animate-persist="true">My app</h1>
  <p>This is specific to my view!</p>
</body>

Note: Elements don't actually persist, the get replaced by the fetched page just like any other element. But because no animation gets applied, they look just as if the persist (as long as the newly fetched page includes the exact same element in the same position).

Setting data-turbo-animate-persist to true will result in the entire element (including its children) being excluded from the applied animations. If you want to apply the animations to children of the persistent element, but still keep it untouched, append -itself to the data attribute. This is especially useful, when you apply a background color to your element, which remains the same, but changes it contents:

<body data-turbo-animate-animation="fadein">
  <nav data-turbo-animate-persist-itself="true" style="background: black;">
    <h1 style="color: white;">View specific title</h1>
  </nav>
  <p>This is specific to my view!</p>
</body>

Animation types

Often your permanent elements depend on the hyperlink clicked. Just specify the animation type on the hyperlink tag, and replace true with the chosen type on the persistent element:

<body data-turbo-animate-animation="fadein">
  <nav data-turbo-animate-persist-itself="nav" style="background: black;">
    <h1 style="color: white;">View specific title</h1>
  </nav>
  <a href="/do" data-turbo-animate-type="nav">Persist navigation!</a>
  <a href="/doo">Don't persist navigation!</a>
</body>

Element transitions

In a lot of cases it can be useful to apply custom CSS transitions to specific elements when the page changes. This works especially well with background colors of persisted elements, but can be used for any CSS property on any element. Multiple properties can be transitioned using using comma separated values.

<header data-turbo-animate-persist-itself="true" data-turbo-animate-transition="background-color,opacity">
  <!-- ... -->
</header>
header {
  transition: 0.25s background-color ease-out;
}

#page1 header {
  background-color: blue;
}

#page2 header {
  background-color: red;
}

When you have a third page, which doesn't contain a header element, the page transition performs normally as this method only applies when Turbo Animate can find a matching element on the new page.

Important: Unless you only use this data attribute for elements that can be distinguished by their HTML tag, you have to declare an id.

Events

Turbo Animate emits events that allow you to track the animation lifecycle. Turbo Animate fires events on the document object.

  • turbo:animation-start fires when an animation starts. The main Turbo Animate element can be accessed with event.data.element. Access the animation with event.data.animation. Access whether content appears or disappears with event.data.disappearing.

  • turbo:animation-end fires when an animation ends. The main Turbo Animate element can be accessed with event.data.element. Access whether content appeared or disappeared with event.data.disappearing.


Testing

  1. Fork this repository

  2. Clone your forked git locally

  3. Install dependencies

    $ yarn install

  4. Run ESLint

    $ yarn eslint


Release

  1. Review breaking changes and deprecations in CHANGELOG.md.
  2. Change the version in package.json.
  3. Reset CHANGELOG.md.
  4. Create a pull request to merge the changes into master.
  5. After the pull request was merged, create a new release listing the breaking changes and commits on master since the last release.
  6. The release workflow will publish the package to NPM and GPR.

To Do

We use GitHub projects to coordinate the work on this project.

To propose your ideas, initiate the discussion by adding a new issue.


Contributing

We hope that you will consider contributing to Turbo Animate. Please read this short overview for some information about how to get started:

Learn more about contributing to this repository, Code of Conduct

Semantic Versioning

Turbo Animate follows Semantic Versioning 2.0 as defined at http://semver.org.