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

react-on-scroll-animation

v1.0.0

Published

ROSA - React on scroll animation based on AOS css files and Intersection Observer api with polyfills

Downloads

28

Readme

about

This library was inspired by great AOS library. It using its style files and core architecture concepts. The main difference is that this library using intersection observer (with polyfills) instead handling events on scroll, and thanks to react architecture don't have to use mutation observer which one have big involvements on performance during dynamic remounting elements by react.

installation

npm install react-on-scroll-animation --save
yarn add react-on-scroll-animation

prop definitions

Rosa.propTypes = {  
  children: PropTypes.element, // react build in  
  anchor: PropTypes.oneOfType([  
      PropTypes.element, // react element  
      PropTypes.string, // css query selector  
  ]),  
  animation: PropTypes.string.isRequired, // animation name string - check below available animations  
  offset: PropTypes.number, // shifting animation init place in px in respect to anchorPlacement  
  delay: PropTypes.number, // animation delay in milliseconds  
  easing: PropTypes.string, // easing - check bellow available easing  
  duration: PropTypes.number, // - in milliseconds  
  disable: PropTypes.oneOfType([  
      PropTypes.oneOf(["tablet", "mobile", "phone"]),  
      PropTypes.bool, // by passing computed value  
      PropTypes.func, // called in response on resize and popstate  
  ]),  
  once: PropTypes.bool, // if true only animation will be called only once  
  anchorPlacement: PropTypes.oneOf([  
	  "top-bottom", // top of element in relative to bottom of window  
	  "top-center", // --""-- in relative to center of window  
	  "top-top",  
	  "center-bottom",  
	  "center-center",  
	  "center-top", // center of element relative of top of window  
	  "bottom-bottom",  
	  "bottom-center",  
	  "bottom-top",  
  ]),  
  animatedClassName: PropTypes.string, // custom animation class name - can be use full with custom animations  
  initClassName: PropTypes.oneOfType([  
      PropTypes.string, // custom init class name - added after component initialization
      PropTypes.bool, // rosa-init class name added after component initialization  
  ]),  
  useClassNames: PropTypes.bool, // if true add animation name as calls to element  
  callback: PropTypes.func, // callback function fired on animation start end rollback  
  debounceDelay: PropTypes.number, // window resize debounce time  
}

default prop values

Rosa.defaultProps = { 
  offset: 0,    
  delay: 0,    
  easing: 'ease',    
  duration: 400,    
  disable: false,    
  once: false,    
  anchorPlacement: 'top-center',    
  animatedClassName: 'rosa-animate',    
  initClassName: 'rosa-init',    
  useClassNames: false,    
  debounceDelay: 100, 
}  

usage

import "react-on-scroll-animation/build/index.css";
/*Animations are based on css files you can easily 
  overwriting it by you own rules, but you have to import 
  css files from build pack separately. 
  You can import or copy this file directly to your sass file as well.*/
import Rosa from "react-on-scroll-animation"  

<Rosa animation="zoom-in"   
      duration={300}   
      delay={500}>  
 {content} </Rosa>  
<Rosa animation="slide-right"   
      anchor="#someId"   
      anchorPlacement="bottom-top"   
      offset={500}   
      initClassName="custom-init-class">  
 {content} </Rosa>  

animations

Fades

  • fade-up
  • fade-down
  • fade-right
  • fade-left
  • fade-up-right
  • fade-up-left
  • fade-down-right
  • fade-down-left

Slides

  • slide-up
  • slide-down
  • slide-right
  • slide-left

Zooms

  • zoom-in
  • zoom-in-up
  • zoom-in-down
  • zoom-in-left
  • zoom-in-right
  • zoom-out
  • zoom-out-up
  • zoom-out-down
  • zoom-out-right
  • zoom-out-left

Flips

  • flip-left
  • flip-right
  • fade-up
  • fade-down

easing

  • linear
  • ease
  • ease-in
  • ease-out
  • ease-in-out
  • ease-in-back
  • ease-out-back
  • ease-in-out-back
  • ease-in-sine
  • ease-out-sine
  • ease-in-out-sine
  • ease-in-quad
  • ease-out-quad
  • ease-in-out-quad
  • ease-in-cubic
  • ease-out-cubic
  • ease-in-out-cubic
  • ease-in-quart
  • ease-out-quart
  • ease-in-out-quart

custom animation

/*style file*/
[data-rosa][data-rosa="custom-animation"]{
  transition-property: transform, opacity;
  transform:  rotate(-100deg) scale(0);
}
[data-rosa="custom-animation"].rosa-animate{
  opacity: 1;
  transform:  rotate(0) scale(1);
}
//import to local component or globally
import "./style.css";
<Rosa animation="custom-animation"  
      duration={2000}>
        {content} 
</Rosa>

/*to have more specific selector enable init class
this allows you overwrite easing duration and delay */  
.rosa[data-rosa][data-rosa="custom-rotating-zoom"]{  
     transition-duration: 690ms; 
     transition-delay: 310ms; 
     transition-property: transform, opacity; 
     transition-timing-function: ease; transform:  rotate(180deg) scale(0);
 }  

.rosa[data-rosa][data-rosa="custom-rotating-zoom"].rosa-animate{  
    opacity: 1; transform:  rotate(0) scale(1);
 }  
<Rosa animation="custom-rotating-zoom"   
      initClassName="rosa" // possibility to write more specific selectors  
      duration={2000}> // this is overwritten by style
        {content} 
</Rosa>  

custom duration, delays and easing

Duration and delays based on value quantization to 50ms. If you need be more accurate you can specify your own value in css.

for duration

[data-rosa][data-rosa-duration = 999]{ transition-delay: 0s}  
[data-rosa][data-rosa-duration = 999].rosa-animate{  
     transition-delay: 999ms
 }  

for delay

[data-rosa][data-rosa-delay = 666]{ transition-delay: 0s}  
[data-rosa][data-rosa-delay = 666].rosa-animate{  
    transition-delay: 666ms
 }  

for easing

[data-rosa][data-rosa=easing="bounce"]{  
    transition-timing-function: cubic-bezier(.61,-1.06,.5,1.83)
}  

callback

callback function get two params

callback(animated: boolean, target: HtmlElement){}  
<Rosa animation="side-left"    
      duration={800}  
      callback={(animated, taregt) => {
          if(animated){
              setTimeout(()=> 
                target.closest(".section__code")
                .style.borderColor = "DarkCyan"
              , 1000)
          }
      }}>
        {content} 
</Rosa>

@param - animated

  • true - if element is animating - thas mean gets .rosa-animate classs
  • false- if class is removed

@param - target

  • HtmlElement which is animated (from IntersectionObserverEntry.target)

disabling

<Rosa animation="side-up"   
      disable="mobile">   
	      {content}
</Rosa>  

@param disable

  • string : "mobile" or "phone" or "tablet"
  • boolean
  • function - it will be called on resize and popstate events

This project was bootstrapped with Create React Library.

All library files are located inside src/lib folder.

Inside src/demo folder, you can test your library while developing.