Socket
Socket
Sign inDemoInstall

reactjs-infinite-scroll-loop

Package Overview
Dependencies
82
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    reactjs-infinite-scroll-loop

React component that supports infinite scrolling of finite number of elements.


Version published
Weekly downloads
12
increased by50%
Maintainers
1
Install size
10.8 MB
Created
Weekly downloads
 

Readme

Source

react-infinite-scroll-loop

demo3

Usage

<InfiniteScrollLoop {/* props here */}>
    <ContentWrapper {/* props here */}>
        {/* Content element 1 */}
    </ContentWrapper>
    <ContentWrapper {/* props here */}>
        {/* Content element 2 */}
    </ContentWrapper>
    ...
</InfiniteScrollLoop>

Animation

Custom animation when a content element is selected can be implemented by adding the custom pseudo class <className>__selected. The animation transition duration can be added to the target <className>.

Example

demo2

The following code snippets reproduce the above gif:

React JS:

const Example = () => {
    return (
        <div style={{ height:"150px", width:"200px" }}>
            <InfiniteScrollLoop>
                {
                    Array(6).fill(0).map((v, i) => {
                        return <Content key={i} id={`${i+1}`} number={i+1}/>
                    })
                }
            </InfiniteScrollLoop>
        </div>
    );
};

interface ContentProps {
    id: string;
    number: number;
}

const Content = ({ id, number }: ContentProps) => {
    return (
        <ContentWrapper height="30%" width="100%">
            <div id={id} className="container" >
                <h4 className="number">{number}</h4>
            </div>
        </ContentWrapper>
    );
};

CSS:

.container {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.number {
    margin: 0;
    opacity: 0.2;
    font-size: 18px;
    transition: 0.2s;
}

.number__selected {
    opacity: 1;
    font-size: 25px;
}

Docs

InfiniteScrollLoop Props

NameTypeDefaultDescription
childrenReact.ReactNodeNone (required)The content of the scroll container.1
onSelect(selected: Element) => voidundefinedExecutes a given JavaScript code on the selected element.
verticalScrollbooleantrueThe direction of scroll. true for vertical and false for horizontal.2
backupnumber50The number of backup content sets on the top and bottom. Increasing this number will increase the amount of scroll required to the end of the scroll container, but decreases performance as more content needs to be rendered.

ContentWrapper Props

NameTypeDefaultDescription
heightstring (accept any CSS height values)‘auto’The height of each content element.
widthstring (accept any CSS width values)‘auto’The width of each content element.

Footnotes

  1. Each content element must be contained in a ContentWrapper, or a custom parent wrapper class that consists of the scroll-snap-align property.

  2. If scrollDirection is vertical, the height of scroll container must be larger than the height of each content element. If scrollDirection is horizontal, the width of scroll container must be larger than the width of each content element.

FAQs

Last updated on 14 Jan 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc