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-page-scroll

v1.0.6

Published

A simple React library for full page scrolling page by page. [Click here for a Demo!](http://react-page-scroll-demo.s3-website-us-east-1.amazonaws.com/)

Downloads

115

Readme

React Page Scroll

A simple React library for full page scrolling page by page. Click here for a Demo!

enter image description here

Installation

Using npm :

npm install react-page-scroll

Using yarn :

yarn add react-page-scroll

Features

  • Full page horizontal and vertical scroll
  • Works on Touchscreens (Mobile/Tablets) and Desktop
  • Nested scroll
  • Easy API
  • Hooks
  • Lightweight (12.6 kB)
  • Fluid CSS based animation

Notice: When using a mobile device and scrolling within a nested scroll section, weak user gestures may result in no scrolling. A fix is in development.

Usage

Simple example:

import  React  from  'react';
import  ReactPageScroll  from  'react-page-scroll';

const  SimpleExample  = () => {
    return (<PageScroll width="100vw" height="100vh">
			<div id="page1" className='page'></div>
			<div id="page2" className='page'></div>
	    </PageScroll>)
};

export  default  SimpleExample;

Demo : Simple scroll

Nested example:

this is nested scroll example where the container scrolls vertically and the nested scroll on page 2 scrolls horizontally:

import  React  from  'react';
import  PageScroll, { NestedPageScroll }  from  'react-page-scroll';

const  SimpleNestedExample  = () => {
    return (<PageScroll width="100vw" height="100vh">
		<NestedPageScroll direction="horizontal" width="100vw" height="100vh">
			<div id="page1-1" className='page'></div>
			<div id="page1-2" className='page'></div>
		</NestedPageScroll>
		<div id="page2" className='page'></div>
	    </PageScroll>)
};

export  default  SimpleNestedExample;

Demo : Nested scroll

Documentation

Content:

1. PageScroll:

Type: (children: ReactNode, Props: PageScrollProps) => ReactNode <PageScroll> is a higher level container for enabling scroll. you can set the scroll direction as horizontal or vertical, the animation duration in ms, the css animation easing and the width and height of the container. You can find more details on the Props section.

<PageScroll> automatically identifies its direct children and designates them as pages for scrolling from or to. This behavior was intended to make its usage simpler. So don't put anything that you don't consider a page as a direct child of <PageScroll>.

<PageScroll> supports nested scroll but through the <NestedPageScroll> component. Using <PageScroll> inside itself will cause an unintended behavior. Also using <NestedPageScroll> outside of a <PageScroll> will throw an error.

Example:

import  React  from  'react';
import  PageScroll from  'react-page-scroll';

const ScrollingPages = () => {
	return (<PageScroll width="100vw" height="100vh">
		    <div id="page1" className='page'></div>
		    <div id="page2" className='page'></div>
	        </PageScroll>)
}

2. NestedPageScroll:

Type: (children: ReactNode, Props: PageScrollProps) => ReactNode <NestedPageScrol> is almost identical to <pageScroll>). With two main differences:

  1. It is used to enable nested scroll inside a <pageScroll>) component in case you need a different direction (to switch from vertical scrolling to horizontal scrolling) or to create a different page indicator for the nested scroll.
  2. It can only be used inside a <pageScroll>). You can nest it inside itself as much as you want as long as you put all of them inside a <pageScroll>). In case you use it alone, it will throw an error.

Example:

import  React  from  'react';
import  PageScroll, { NestedPageScroll } from  'react-page-scroll';

const ScrollingPages = () => {
	return (<PageScroll width="100vw" height="100vh">
			<NestedPageScroll direction="horizontal" width="100vw" height="100vh">
				<div id="page1-1" className='page'></div>
				<div id="page1-2" className='page'></div>
			</NestedPageScroll>
			<div id="page2" className='page'></div>
	        </PageScroll>)
}

3. Props:

  1. direction (Optional)(default: "vertical"):
    • description: Sets the scroll direction, supports only "vertical" or "horizontal"
    • type: "vertical" | "horizontal"
  1. width (Optional)(default: "100vw"):
    • description: Sets the width of the scroll container, supports any valid CSS width value.
    • type: String
  1. height (Optional)(default: "100vh"):
    • description: Sets the height of the scroll container, supports any valid CSS height value.
    • type: String
  1. animationDuration ~in ms (Optional)(default: 300):
    • description: Sets the duration of the scroll animation in ms. Supports any positive number
    • type: Number
  1. animationEasing (Optional)(default: "cubic-bezier(0.76, 0, 0.24, 1)"):
    • description: Sets the easing of the scroll animation. Supports any valid CSS animation easing.
    • type: String

Hooks: check this demo for an example with hooks! -- Live preview

  1. onScrollInit (Optional):
    • description: A function that is called whenever the component will be handling the scroll. the function receives the current child index, number of the scrolling container children and a scroll control object to programmatically launch a scroll as a parameter. Notice: the same scroll control object will be given inside a <PageScroll> component.
    • type: (args: { currentChildIndex: number; numberOfChilds: number; scrollControl: ScrollControls; }) => void
    • scrollControl has three methods:
      • scrollTo: that receives the target you want to scroll to;
      • scrollToNext: scroll into the next child depending on the direction you've set;
      • scrollToPrevious: scroll into the previous child depending on the direction you've set;
  1. onScrollStart (Optional):
    • description: A function fired when a scroll is about to happen. the function receives an object with the target index as a parameter (the index of the page it will scroll into, relative to all its siblings) . this is particularly useful if you want to do something in parallel with the scroll like setting the page indicator.
    • type: (args: { targetIndex: number }) => void
  1. onScrollEnd (Optional):
    • description: A function fired when a scroll has ended. the function receives an object with the current index as a parameter (the index of the current showing page relative to all its siblings) . this is particularly useful if you want to do something after a scroll has ended.
    • type: (args: { currentIndex: number }) => void
  1. onScrollCommandCede (Optional):
    • description: A function fired when the scroll will no longer be handled by the <PageScroll> or the <NestedPageScroll> component you passed the function into as it is passing control to another child or parent scroll component. the function receives an object with the last page index before ceding control as a parameter.
    • type: ({ container: HTMLElement; currentChildIndex: number; numberOfChilds: number; }) => void

Contributing

Contribution is welcome. If you have an idea or found a bug, please open an issue. For code contributions, fork the repository and submit a pull request.

License

React Page Scroll is licensed under the MIT License.