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

leo-animate.js

v1.0.8

Published

Input animation and scrolling with the Intersection Observer API.

Downloads

25

Readme

leo-animate.js

en pt-br

⚠️ Warning

This readme was written primarily with Google Translate. I'll be happy if you make an exception for any grammatical errors!

🔎 Introduction

leo-animate.js is a JavaScript module that uses the IntersectionObserver API to apply animations on the page according to the elements are visible in the viewport.

leo-animate.js is a modern alternative to apply scroll animations and page enter animations asynchronously, ensuring that the user sees the defined transitions.

🚀 Get started

This repository is distributed with the npm package manager. Perform the Installation of Node.js which already has npm as default package manager.

Installation

npm i leo-animate.js

Include the CSS

At the top of your stylesheet, include:

@import "/node_modules/leo-animate.js/dist/leo-animate.css"
layer(leo-animate.js);

layer() is just to create a new cascade layer to identify the styles applied by leo-animate.js. You must delete it in production or if you are importing the styles with SASS.

Include the JavaScript

At the top of your module-like script file, include:

import LeoAnimate from "/node_modules/leo-animate.js/dist/leo-animate.js"

Instantiate the class

new LeoAnimate();

You might want to refer to some usage examples with React!

Usage

Ready! You can already use the data-animate attribute on the element you want to animate with the default values: fadeDown, fadeUp, fadeRight and fadeLeft.

<h1 data-animate="fadeRight">
    leo-animate.js
</h1>

Responsive attributes are also available: sm, md, lg, xl, xxl.

<p data-animate="fadeRight"
data-animate-lg="fadeDown">
    leo-animate.js
</p>

NOTE: If you want to use only the responsive attributes, you must specify at least data-animate with no value to apply the animations.

💻 Features

Discard the onscroll event

As leo-animate.js uses the IntersectionObserver API to observe when an element is visible in the viewport and only then execute something, the onscroll event is completely unnecessary, making it unnecessary to execute a function several times according to the user's scroll.

Ensure animation visibility

Using IntersectionObserver also ensures that the animation does not run if the user enters the page but minimizes the window or switches tabs in their browser.

Tab switching example

Fully Responsive

leo-animate.js uses a custom attribute called data-animate to apply the animations. This attribute can contain several variations for specific breakpoints, making it possible to use different animations depending on the desired media query.

Setting animations in HTML:

<h1 class="app__title"
data-animate="fadeRight"
data-animate-md="fadeDown">
    leo-animate.js
</h1>

CSS compiled:

[data-animate=fadeRight] {
    transform: translate3d(-15px, 0, 0);
    opacity: 0;
}
@media (max-width: 767.98px) {
    [data-animate-md=fadeDown] {
    transform: translate3d(0, -15px, 0);
    opacity: 0;
    }
}

This is an example of using the default settings of leo-animate.js, but you can configure both the media query itself and the name of the media query to use in the (data-animate-custom) attribute.

Highlight each element

If there is more than one visible element where the animation would run at the same time as another element, a delay is automatically applied to the animation.

In the gif below, for example, a specific delay was NOT manually set for the animation of each element:

Demonstration of automatic applied delay

Adaptable to reduced motion preferences

leo-animate.js ensures that none of the animations are styled and the JavaScript itself is omitted with those who prefer to override animations.

Demonstration of animations on and off on Windows

📋 Builder Options

The LeoAnimate constructor receives an optional object as an argument that allows configuring how the animations will occur. If you want to configure other types of animations or customize breakpoints, configure SASS from leo-animate.js.

In the LeoAnimate object, the following properties are available:

| Property | Type | Description | | ------------------------- | --------- | ----------- | | infinite | boolean | Sets whether animations will recur after the page has been scrolled up. The default value is false. | multipleElementsDelay | number | Sets a delay in milliseconds for the animation to occur between elements that are displayed at the same time. Setting a positive number allows you to use a sync-special-attribute on elements. The default value is 400. | transitions | object | Object containing the CSS transition properties that will be applied to all elements. See customizing transitions.

Sync special attribute

data-animate-sync e data-animate-id

When the constructor's multipleElementsDelay property has a positive number, it is possible to use the data-animate-sync attribute to apply the same animation delay to an element as another element.

Use data-animate-id to give a unique name to the element you want to copy the animation delay. Now just give the element that you are going to synchronize the delay with the same id as the value of data-animate-sync.

To be clearer, consider the following example:

Demo without sync attribute

Now see the same example where the first element / cell of each column has data-animate-id with a unique id and each element below has data-animate-sync pointing to the respective id.

Demo without sync attribute

Customizing transitions

transitions e data-animate-{transition}

The transitions object of the constructor applies the transitions mentioned below to all elements. However, you can also use the same key names in the data-animate attribute on a specific element to override the global transition defined in the constructor.

All values are given a string that must represent a valid CSS value.

| Property | Equivalent attribute | Description | | -----------------| -----------------------| ----------- | | duration | data-animate-duration | Sets the time the animation(s) takes to complete. The default value is "600ms". | timingFunction | data-animate-timingFunction | Defines the timing function of the animation(s). The default value is "ease".