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

@liaoys/parallax

v1.0.1

Published

A JavaScript library that makes parallax animations for a website.It effects for any elements and any css style that has number value

Downloads

1

Readme

@liaoys/parallax

A JavaScript library that makes parallax animations for a website.It effects for any elements and any css style that has number value.

example1


example2


See example

Installation

npm install @liaoys/parallax

Usage

<div id="parallax-container">
    <div class="parallax-element"
         parallax-start-style="transform: translate(0,0)"
         parallax-end-style="transform: translate(100px,0)"
    >element1</div>
    <div class="parallax-element"
         parallax-start-style="transform: translate(0,0)"
         parallax-end-style="transform: translate(-100px,0)"
    >element2</div>
    <div class="parallax-element"
         parallax-start-style="opacity:1"
         parallax-end-style="opacity:0"
    >element3</div>
</div>
import Parallax from "@liaoys/parallax";

const parallax = new Parallax({
  container: '#parallax-container',
  startTop: 200,
  endTop: 0,
})

In the example above, when the "parallax-container" scrolls from the top 100 of the viewport to 0:

"element1" will move 100px to the right

"element2" will move 100px to the left

"element1" will transition from opaque to transparent

See example

Types

Type: Parallax

Instance of class Parallax

Type: ParallaxSelector

string | HTMLElement | Array<HTMLElement> | ArrayLike<HTMLElement>

Be use for select an element

Options

| Name | Type | Default | Description | | ---- | ---- | ---- | ---- | | container | ParallaxSelector | | Parallax container. Required by default | | elements | ParallaxSelector | .parallax-element | Animation elements | | elementAttrPrefix | string | parallax | Animation Element's attribute prefix | | startTop | number | 0 | The distance of the container from the top of the viewport at the beginning of animation | | endTop | number | 500 | The distance of the container from the top of the viewport at the end of animation | | scrollElement | ParallaxSelector | document | If page's scroll element is not Document Object, use this option to specify a new | | customProgress | boolean | false | Enable "customProgress" mode. In this mode, the animation progress will not base on scroll. It need to call the 'update' method to set(see example). The options container, startTop and endTop will be invalid | | on | object | | Add event listener |

Element's Attributes

| Name | Default | Description | | ---- | ---- | ---- | | parallax-start-style | | The style of animation start | | parallax-end-style | | The style of animation end | | parallax-start-progress | 0 | The progress of animation start | | parallax-end-progress | 1 | The progress of animation end |

Instance properties

| Name | Type | | Description | | ---- | ---- | ---- | | container | HTMLElement | Parallax container | | options | object | Parallax initial options | | progress | number | current progress of the Parallax animation |

Instance methods

update(progress?: number, triggerProgressEvent = false): Parallax

  • progress Animation progress. By default, progress will calculate automatic by the distance of the container from the top of the viewport.
  • triggerProgressEvent Trigger the event Named progress

on(eventName: string, listener: () => void): Parallax

  • eventName The name of the event
  • listener The callback function

Add event listener

Events

Parallax comes with a bunch of useful events you can listen. Events can be assigned in two ways:

1.Using on options on parallax initialization:

const parallax = new Parallax( {
  // ...
  on: {
    init: function () {
      console.log('parallax initialized');
    },
  },
});

2.Using on method after parallax initialization.

const parallax = new Parallax({
  // ...
});
parallax.on('progress', function (parallax, progress) {
  console.log(`The current progress is ${progress}`);
});

| Name | Arguments | Description | | ---- | ---- | ---- | | init | (parallax: Parallax) | Event will be trigger after a initialization | | progress | (parallax: Parallax, progress: number) | Event will be trigger when Parallax progress is changed. Argument progress is always from 0 to 1|