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

scroll-dom-animation

v1.0.9

Published

Makes animating dom elements on scroll event super easy using a declarative approach without having to touch your css

Downloads

10

Readme

scroll-dom-animation

utalizing a declarative approach, this library makes animating dom elements on the scroll event super easy.

sample

                                  selector    animation direction
                                      |           |
                                      v           v
                                  
  scrollDomAnimation.animate([ '.class__name',   '->'])

install

npm install scroll-dom-animation  

content:

-live demo

-introduction

-syntax

-directions

-options

-smoothscroll

Introduction

While working on a project, I came up with this package to help me simplify and visualize my JS scroll animations in one spot without having to mess with css files and this is exactly what this library does (see the code used for the demo below).

when you style your elements you would place them in their intended final position (after animation) and our library takes care of animation.

There are three benefits to this approach:

  • you can use this library on an existing project or on top of other libraries (e.g. bootstrap) without touching any css.
  • If the client's browser didn't load Js files for some reason, your application will display as intended.
  • easy to change library in the future since your own code will not be changed.

NOTE: don't use this library for element that will appear in the top view when page loads. Only use it for elements that will appear on scroll. This is because our library has to initiat position through JS before animating which will show if element is in view when loaded.

Syntax

1. animating elements with one selector (classname, id, etc...):


animate([selector, direction, options])

selector could be any css selector. Direction could be any symbol from the direction table below. Options is an object that is used to adjust animation.

2. animating multiple elements with different selectors:


animate(Array[elementToAnimate]) 

To animate multiple selectors you can wrap them in an array and provide this array as an argument. Check the example below:

Example

const elementsToAnimate = [
    ['.class__name1', '<-'], 
    ['.class__name2', '^'],
    ['.class__name3', '<-' {time: 0.5}]
];

scrollDomAnimation.animate(elementsToAnimate);

Directions

NOTE: the opposit direction symbols below only work on selectors that return multiple elements. In other word, multiple elements that share the same class/id name will be animated in opposit direction consecutively.

| symbol | discription | |---------|----------------------------------| | -> | to right | | <- | to left | | -><- OR <--> | consecutive elements in opposit direction | | ^ | upward | | v | downward | | ^v OR v^ | consecutive elements in opposit direction | | /^ | upward to right | | v/ | downward to left | | v//^ | consecutive elements in the opposit direction | | * | fadein | | .o | scaleup | | o. | scaledown | | .oo. OR o..o | consecutive elements in opposit direction |

options

In addition to the selector and direction properties shown in the examples above, each selector array takes a 3rd options object (optional) to customize the animation of the corresponding element.

                                                         options
                                                        |        |
                                                        v        v
scrollDomAnimation.animate(['.class__name1', '<-', { time: 1, offset: 80 }]);

time : sets transition time of the animation in seconds - default 0.3
offset : animation distance in pixels - default 50
scaleFactor : only works on scale animations such as '.o'. default - 'o.': 0.1 | '.o': 0.5
inViewDistance: the amount of pixels the element has to be in view before animating.
elementIndex : if more than one element share the same selector, this defines which elements to apply animation to.

live demo

VIEW DEMO

All animations in the demo are done through this library using this exact code:

const elementsToAnimate = [
    ['.project__img', '-><-', { time: 0.4 }], 
    ['.project__num', '-><-', { time: 0.5 }],
    ['.projects__header', '^'],
    ['#about .card', 'o.', {time: 0.4}],
    ['#about .card-title', '.o', {scaleFactor: 0.5}],
    ['#about .card-text', '*', {time: 0.8}],
    ['#resume .card', '^'],
    ['#resume .card-link', '->', { time: 0.7}],
    ['#connect .btn', '^v', {time: 0.5, offset: 20},], 
]

scrollDom.animate(elementsToAnimate);

Smooth scroll

const projectBtn = document.querySelector('.project__btn');

projectBtn.addEventListener('click', scrollDomAnimation.smoothScroll);

This library provides you a method that you can use as a callback on the btn or link that contains the href of the target as shown in the code above.

Under the hood it uses scrollIntoView which is not supported by all browsers so make sure it works for you before using.

Contribution

You are welcome to contribute to this package. To add more animations please checkout the /lib/animations.js module and feel free to suggest more animations.