0.4.0 • Published 3 years ago

simple-scroll-animate v0.4.0

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

Logo

Simple Scroll Animate

npm version

A lightweight library that allows you to add animation classes to elements as they appear in the viewport. Make a fancy animation play as you scroll to it.

Under the hood, it simply utilises the Intersection Observer API and applies your CSS classes as you scroll into view.

🚀 Getting started

Install with npm or yarn

npm install simple-scroll-animate --save

Supply the list of HTML elements you are wanting to track in the viewport and animate.

const scrollAnimator = new ScrollAnimator();
scrollAnimator.create(document.querySelectorAll(".animate"));

Add data-animate-class='your-css-class-name' to your html element. Pass in the CSS class to be applied when the element comes into view. See the full list of options here.

<div class="animate" data-animate-class="animate-fade-in">
    Fancy fade in animation!
</div>
@keyframes fadeIn {
    0% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}

.animate-fade-in 
{
    animation: fadeIn .5s linear both;
}

Examples & Demo

For a full list of examples, view an example. To view a demo, click here

Configuration

There are a few options you can apply to your elements.

ConfigDescriptionDefaultRequired
data-animate-class="your-css-classname"The CSS classname you want applied to your element when it comes into viewanimate-inoptional
data-animate-once="true"Play the animation once, emit to always re-play the animation when in viewfalseoptional
data-animate-threshold="0.5"A value of 1.0 means that the your CSS animation will not play until every pixel of the element is visible in the viewport. The default, 0.5, will play your animation if the visibility passes 50%.0.5optional
data-animate-root-margin="50px"Margin around the element before triggering animation. Can have values similar to the CSS margin property, e.g. "10px 20px 30px 40px"no-animationNo
data-animate-delay-seconds="0.1"The delay in seconds before playing an animation0No

📝License

This project is licensed under the MIT License - see the LICENSE.md file for details

0.3.0

3 years ago

0.2.0

3 years ago

0.4.0

3 years ago

0.1.0

3 years ago