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

simple-scroll-animation

v1.0.4

Published

On scroll animation library

Downloads

10

Readme

SSA - Simple Scroll Animation

This Library lets you simply add any animation based on the scroll position of an element. It's just the basics and nothing more complex, so the minified version is only 3kB big.

Installation

To use this library in your project just download ssa.js or the minified version ssa-min.js from the /dist directory and include it in your project.

Or if you want include it via a CDN:

<script src="https://unpkg.com/[email protected]/dist/ssa-min.js"><script/>

Or with NPM:

npm i simple-scroll-animation

Sample Project

In the examples folder is a sample project to show you how it works and what you can do with the library. Just clone this repository and open up the index.html.

Usage

To add an animation to an element you have to give it an ID. The AnimationObject creates an animation object of your element. You can start the animation by calling the start() function of the animation object.

new Scroll.AnimationObject(elementId, style, endValues, endOffset, startValues, startOffset, unit).start();

The elementId and style must be provided. The rest of the arguments are optional.

| Argument | Description | Type | Default | |:-------------:|:-------------:|:-----:|:-----:| | elementId | The Id of the element (without #)| String | No default | | style | Object with the css property and a valueMapper | Object {property: String, valueMapper: function} | No default | | endValues | Numbers in an array that represent the value at the end of the animation | Array(Numbers)| [0] | endOffset | Offset from the bottom of the viewport where the animation should end (in percent 0-1) | Number | 1 | startValues | Numbers in an array that represent the value at the start of the animation | Array(Numbers) | [0] | startOffset | Offset from the bottom of the viewport where the animation should start (in percent 0-1) | Number | 0 | unit | The unit that is used (px, em, %)| String | px

Style

The style defines what css property gets changed.

{
   property: 'string', 
   valueMapper: 'function'
}

The property is used to change the style object of an node. It has to be lower camel case f.e. BackgroundColor, borderRadius, ...

The value mapper is a function that returns the value. The mapper gets the values and the unit as an argument.

For example:

{
  property: "transform",
  valueMapper: function(vals, unit){
      return `rotate(${vals[0] + unit})`  
  }
}

{
  property: "transform",
  valueMapper: function(vals, unit){
      return `scaleX(${val[0]}) translateX(${vals[1] + unit})`  
  }
}

Offset

The offset is the distance in percent from the bottom of the viewport to the top of the element.

0 -> 0% and 1 -> 100%.

F.e. you set startOffset to 0, than the element starts to animate after the element is shown on the screen. When you set endOffset to 1 the animation stops after the top of the element passes the top of the viewport.

Predefined Animations

There are several predefined animations that are creating an AnimationObject, so you don't have to write every time a style. These functions take the same arguments as the AnimationObject except they don't take a style and the values don't have to be an array.

Scroll.width(elementId, endValue, endOffset, startValue, startOffset, unit)
Scroll.height(...)
Scroll.opacity(...)
Scroll.bottom(...)
Scroll.top(...)
Scroll.left(...)
Scroll.right(...)
Scroll.rotate(...)
Scroll.scale(...)
Scroll.scaleX(...)
Scroll.scaleY(...)
Scroll.translateX(...)
Scroll.translateY(...)

You can set different animations on the same element, as long the property is not overridden, like it is the case with scale and translate. In that case you have to write your own mapper function with two values.

Scroll.opacity("element", 1, 0.5).start();
Scroll.rotate("element", 180).start();

Extra

Unit and the start/end points can also be set with a setter function that supports chaining.

Scroll.opacity("element")
    .setStart({value: 0.5, offset: 0.1})
    .setEnd({value: 1, offset: 0.9})
    .start();

Author

License

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