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

lottie-play-on-scroll

v1.0.1

Published

This package will makes you could play lottie animation by scroll mouse wheel on PC or touch scrolling on mobile devices

Downloads

4

Readme

LottiePlayOnScroll

LottiePlayOnScroll could help you to play lottie animation forward/backward base on user scroll the mouse wheel on PC or touch/drag on mobile screen.

Demo

Mar-27-2024 22-07-18

Demo Links:

  1. React.js demo
  2. Vanilla.js demo

Example Project

  1. React.js example
  2. Vanilla.js example

Installation

Install through npm:

npm install lottie-play-on-scroll

Usage

React.js

You should install @lottiefiles/react-lottie-player yourself, then integration with lottie-play-on-scroll

import { useRef } from 'react'
import { attachScroll } from 'lottie-play-on-scroll'
import { Player } from '@lottiefiles/react-lottie-player'

function App() {
  const lottieWrapper = useRef<HTMLDivElement>(null)

  return (
    <div ref={lottieWrapper}>
      <Player
        autoplay={false} // suggest turn off autoplay
        loop={true}
        controls={false}
        src="https://lottie.host/7401522f-2d8b-4049-ad18-eb0edb6af224/CE9lFrNlEH.json"
        lottieRef={(animation) => {
          if(lottieWrapper.current) attachScroll(animation, lottieWrapper.current)
        }}
      />
    </div>
  )
}

export default App

Vanilla.js

<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>lottie play on scroll vanilla example</title>
  </head>
  <body>
    <div id="lottie"></div>
    <script type="module" src="/your/path/main.js"></script>
  </body>
</html>
# main.js
import { loadLottie } from 'lottie-play-on-scroll'

loadLottie({
  container: document.getElementById('lottie'),
  renderer: 'svg',
  loop: true,
  autoplay: false,
  path: 'https://lottie.host/7401522f-2d8b-4049-ad18-eb0edb6af224/CE9lFrNlEH.json' // or '/lottie/data.json'
})

Document

loadLottie

loadLottie(parameters, config);

|name|optional|note| |-|-|-| |parameters|must| The parameters as same as what you pass into lottie.loadAnimation, the only different is the type of container must be kind of HTMLElement | |container|must|The container which wrapper the lottie animation, must be kind of HTMLElement, the wheel/touchmove event listener will be bind on it | |config|optional|like below defaultConfig|

attachScroll

attachScroll(animation, container, config);

|name|optional|note| |-|-|-| |animation|must|lottie instance| |container|must|The container which wrapper the lottie animation, must be kind of HTMLElement, the wheel/touchmove event listener will be bind on it | |config|optional|like below defaultConfig|

config

Due to when user scroll the mouse wheel or drag on screen, the wheel or touchmove will be fire much times, for performace optimization and speed adjustment, we could use pcEventRate and mobileEventRate config to adjust the play speed of animation

const defaultConfig = {
  speed: 50, // backward/forward 50 milliseconds every animation play
  pcEventRate: 1, // every 1 event will play 50 (config.speed) milliseconds animation 
  mobileEventRate: 3, // every 4 event will play 50 (config.speed) milliseconds animation
};

Related Projects

Development

Getting Start

Follow below commands to start development

npm install # install lottie-play-on-scroll project package
npm run build:watch # build lottie-play-on-scroll to js when code change
npm link # set lottie-play-on-scroll as local npm package
cd ./examples/react # or ./examples/vanilla
npm install # install lottie-play-on-scroll/vanilla project packages
npm run link # load local lottie-play-on-scroll npm package
npm run dev # run dev server

Build

npm run build
npm run build:watch

Publish

npm login
npm publish --dry-run
npm publish

Reference