0.9.2 • Published 8 months ago

js-scroll-animations v0.9.2

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

⭥ JS Scroll Animations

License: MIT

JS Scroll Animations is a simple and lightweight library for scroll animations. Follow the instructions below to set it up.

Highlights

  1. Vanilla JS
  2. Easy setup using HTML dataset property
  3. JS Actions
  4. CSS Animations

Instructions

1. Install or download the package

Download or install the package using a package manager:

yarn add js-scroll-animations

or

npm i js-scroll-animations

2. Import the package assets

In your HTML file, add the following link and script tags:

<link
  rel="stylesheet"
  href="../node_modules/js-scroll-animations/dist/styles.css"
/>
<script src="../node_modules/js-scroll-animations/dist/js-scroll-animations.js"></script>

Alternatively, if you are using a module bundler, you can import the assets in your JavaScript file:

import jsScroll from "js-scroll-animations";
import "js-scroll-animations/dist/styles.css";

3. Add the dataset property to the elements you want to animate

Add the data-jsscroll property to activate the scroll animation for an element. You can use other dataset properties to configure the animation, such as data-jsscroll-delay and data-jsscroll-threshold. For example:

<div
  data-jsscroll
  data-jsscroll-delay="200"
  data-jsscroll-threshold="1"
  data-jsscroll-slide-top
  class="box"
>
  content
</div>

4. Initialize the animations

Initiate the animations with the following code:

const jsScroll = jsScrollAnimations();
jsScroll.init();

That's it! Check the demo page to see how it works and how to set it up.

Properties

The following table shows the available dataset properties that you can use to configure the scroll animations:

PROPERTYDEFAULTDESCRIPTION
data-jsscrollActivate scroll animation for the element. A fade-in animation will be used as the default.
data-jsscroll-delay0A delay to trigger the animation when the element is in the view.
data-jsscroll-threshold1.25Threshold to adjust when the animation will be triggered based on the element's y position and the view.
data-jsscroll-fade-inFade-in animation.
data-jsscroll-slide-topSlide from the bottom to the top of the element position animation.
data-jsscroll-slide-bottomSlide from the top to the bottom of the element position animation.
data-jsscroll-slide-leftSlide from the left to the right of the element position animation.
data-jsscroll-slide-rightSlide from the right to the left of the element position animation.

Actions

The following table shows the available JS actions available to control the animations:

ACTIONDESCRIPTION
initInitiate the scroll animations.
pausePause the scroll animations for the non-triggered animations. Use init to resume the animations.
resetResets all elements to their non-animated state, which will trigger the animations again when scrolled to.
disableDisables all animations, making all elements visible.

This project was created by Wander Lima and is licensed under the MIT license.

0.9.2

8 months ago

0.9.1

8 months ago

0.9.0

1 year ago