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

super-simple-scroll-animations

v1.0.3

Published

Intersection observer-based CSS scroll animations

Downloads

3

Readme

Super Simple Scroll Animations (SSSA)

npm badge

SSSA uses intersection observers to detect when an element becomes visible, adding an is-visible class which triggers a CSS-powered animation. Optionally it can remove the class to trigger an exit animation.

Its aim was to provide a lightweight, dependency-free, and extensible approach to detecting when an element comes into view and animating it.

Usage

JavaScript

Import

import superSimpleScrollAnimations from 'super-simple-scroll-animations';

superSimpleScrollAnimations(0.3, false).init();

SSSA accepts two parameters:

  • threshold - Decimal to indicate at what percentage of the target's visibility the observer's callback should be executed, default 0.3
  • enableExitAnimations - When enabled it removes the is-visible when the element exits the viewport, default false

Inline

<script>
  window.sssa = {
    threshold: 0.3,
    enableExitAnimations: false,
  };
</script>

<script src="sssa.min.js"></script>

You will need to declare window.sssa.threshold and window.sssa.enableExitAnimations to change the defaults when using the script inline.

HTML

Elements you wish to be animated should have the attribute js-sssa added. When an element with js-sssa comes into view the is-visible class will be added to it.

<!-- Element will fade in when it passes the threshold -->
<div class="foo" js-sssa="fadeIn">
  Lorem ipsum dolor sit amet...
</div>

<!-- Sub-elements will fade in when parent passes the threshold -->
<ul class="foo" js-sssa>
  <li data-sssa="fadeIn">Lorem ipsum dolor sit amet...</li>
  <li data-sssa="fadeIn">Lorem ipsum dolor sit amet...</li>
  <li data-sssa="fadeIn">Lorem ipsum dolor sit amet...</li>
</ul>

Staggering the animations

To stagger the animations you will need to add a transition-delay property to your elements, either using CSS or inline.

In the example below we use Vue; it's assumed you're using a templating language to handle iteration.

<ul js-sssa>
  <li
    v-for="(person, index) in people"
    :key="index"
    :style="`transition-delay: ${(0.15 * index)}s;`"
    data-sssa="fadeIn"
  >
    {{ person }}
  </li>
</ul>

CSS

The module comes with a set of default animations, the animation used is determined by the value of the attribute added to the element.

@import '~super-simple-scroll-animations/css/sssa';

Movement is achieved using transform: translate(). Properties are transitioned using the CSS transition property. All transitions use cubic-bezier(0.42, 0, 0.58, 1) easing and a duration of 0.6s.

  • fadeIn - Fades in.
  • fadeDirectionUp - Moves up as it fades in.
  • fadeDirectionDown - Moves down as it fades in.
  • fadeDirectionLeft - Moves left as it fades in.
  • fadeDirectionRight - Moves right as it fades in.

Adding your own animations

Simply add the below CSS for each custom animation you want, replacing fade and opacity with your own animation name and property to transition.

.sssa-enabled [js-sssa=fade],
.sssa-enabled [data-sssa=fade] {
  opacity: 0;
  transition: opacity 0.3s ease;
}

[js-sssa=fade].is-visible,
.is-visible [data-sssa=fade] {
  opacity: 1;
}

The .sssa-enabled class is added to the <body> element on load ensuring that users with JavaScript disabled are not presented with invisible elements.

Browser compatibility

| Chrome | Edge | Firefox | IE | Opera | Safari --- | --- | --- | --- | --- | --- | 51+ | 15+ | 55+ | X | 38+ | 12.1+

See MDN's page on intersection observer for full details.

For Internet Explorer support you will need to use a polyfill.