React scrollable component

React scrollable component DEFAULT

Scroll a React component into view

React has an easy way to access DOM APIs of HTML elements through references. We learn how React exposes HTML elements by scrolling an element into view on the click of a button.

People’s behavior on websites did not change very much since the early days of the internet. But one thing that did change - since 1994 to be more precise - was that we learned to scroll longer pages of content. We are now used to websites where not all information may be visible at first sight.

But how do we grab a user’s attention for something that isn’t visible in the current part of the viewport it’s currently looking at. We can utilize a very handy browser API for that, called . Which does exactly what it says it does with a few nice options to modify its behavior.

Scroll to element with plain HTML

Before diving into the React implementation, let’s try out the API on a simple HTML list with vanilla JavaScript.

Let’s say we have an article with a long text.

Whenever a user reached the end of the article, we would like to provide a button to scroll back to the top of the article. This can be achieved by adding a link with the id of the heading element on the end of the paragraph.

Now when the user clicks the link, the browser will automatically jump back to the title element and the user is back on the top of the article. This is the basic way to scroll an element into view without using any JavaScript at all.

Scroll to element with vanilla JavaScript

To scroll to the element with JavaScript, you can create a button which scrolls back the the top when a user clicks it.

By using an event listener on the button, whenever it is invoked we get the heading element by its identifier and tell it to scroll into the browser’s viewport.

For most use cases, this is sufficient. But sometimes you’ll would like to have a nice animation while scrolling. Luckily you can pass additional options to the method to do exactly that.

By setting the option to , the browser will gently scroll to the element instead of the instant jump.

Scroll to a React element

Now the next step is to figure out how we can apply this smooth scrolling behavior on a React component. We can still use the method, but we need to grab the component’s underlaying HTML element to access it.

First, let’s convert our example to a React functional component.

We could still give the element an id attribute. But to do it the React way, we’ll give a reference instead with the hook. You can read more about the useRef() hook in the official React documentation.

Now we need to handle the user clicking the button to scroll back to the top. We can use an event handler for that. You can read more about event handling in the official React documentation.

Within the event handler, we now have access to the title element through its reference. And we can scroll to the title element like we did in the vanilla JavaScript example.

By using in a React component, we have an entry to the underlaying HTML element. This gives us full access to all of the powerful DOM APIs.

Scroll to a React component

Now that we have seen how we can scroll to an element by using a reference. We can utilize that same method to scroll to a React component. By forwarding the reference to the root element of the component, we again have access to the HTML element from outside the component.

As you may see in the example, we’ve used the method, to allow other components to access HTML elements within our Article component by reference. You can read more about the forwardRef() method in the official React documentation.

Bonus: scroll to the first error in a Formik form

To apply what we’ve learned to a real-world use case. Let’s imagine we have a large React form using the Formik library to handle submission and validation. For example the following newsletter signup form.

When a user tries to submit the form, it will display an error saying that the email field is required. In this small form the user will notice this immediately. But when the form grows larger, it would be nice to scroll the error into the viewport so the user notices the error.

We can do this by creating a small helper component that we add to the form.

Now add this component to our Formik form and the user is automatically scrolled to the first input that has a validation error.

Closing thoughts

By using and in your React applications, you will have a lot of powerful DOM APIs at your disposal. In this article we’ve only focussed on , but there are many more cool and handy methods you can use. Did you know that you can even animate elements through JavaScript? The MDN web documentation will tell you more about this method.


Webmentions

  1. Scrolling to a React component #react #js robinvdvleuten.nl/blog/scroll-a-…

Sours: https://robinvdvleuten.nl/blog/scroll-a-react-component-into-view/

npm

React component for animating vertical scrolling

Install

$npminstallreact-scroll

Run

$npminstall$npmtest$npmstart

Examples

Checkout examples

Live example

Basic

Basic-Keydown

Container

With-hash

With-overflow

Code

Usage

// ES6 Importsimport*asScrollfrom'react-scroll';import{Link,Button,Element,Events,animateScrollasscroll,scrollSpy,scroller}from'react-scroll'// Or Access Link,Element,etc as followsletLink=Scroll.Link;letButton=Scroll.Button;letElement=Scroll.Element;letEvents=Scroll.Events;letscroll=Scroll.animateScroll;letscrollSpy=Scroll.scrollSpy;// ES5varReact=require('react');varScroll=require('react-scroll');varLink=Scroll.Link;varButton=Scroll.Button;varElement=Scroll.Element;varEvents=Scroll.Events;varscroll=Scroll.animateScroll;varscrollSpy=Scroll.scrollSpy;varSection=React.createClass({componentDidMount: function(){Events.scrollEvent.register('begin',function(to,element){console.log('begin',arguments);});Events.scrollEvent.register('end',function(to,element){console.log('end',arguments);});scrollSpy.update();},componentWillUnmount: function(){Events.scrollEvent.remove('begin');Events.scrollEvent.remove('end');},scrollToTop: function(){scroll.scrollToTop();},scrollToBottom: function(){scroll.scrollToBottom();},scrollTo: function(){scroll.scrollTo(100);},scrollMore: function(){scroll.scrollMore(100);},handleSetActive: function(to){console.log(to);},render: function(){return(<div><LinkactiveClass="active"to="test1"spy={true}smooth={true}offset={50}duration={500}onSetActive={this.handleSetActive}> Test 1 </Link><LinkactiveClass="active"to="test1"spy={true}smooth={true}offset={50}duration={500}delay={1000}> Test 2 (delay) </Link><LinkclassName="test6"to="anchor"spy={true}smooth={true}duration={500}> Test 6 (anchor) </Link><ButtonactiveClass="active"className="btn"type="submit"value="Test 2"to="test2"spy={true}smooth={true}offset={50}duration={500}> Test 2 </Button><Elementname="test1"className="element"> test 1 </Element><Elementname="test2"className="element"> test 2 </Element><divid="anchor"className="element"> test 6 (anchor) </div><Linkto="firstInsideContainer"containerId="containerElement"> Go to first element inside container </Link><Linkto="secondInsideContainer"containerId="containerElement"> Go to second element inside container </Link><divclassName="element"id="containerElement"><Elementname="firstInsideContainer"> first element inside container </Element><Elementname="secondInsideContainer"> second element inside container </Element></div><aonClick={this.scrollToTop}>To the top!</a><br/><aonClick={this.scrollToBottom}>To the bottom!</a><br/><aonClick={this.scrollTo}>Scroll to 100px from the top</a><br/><aonClick={this.scrollMore}>Scroll 100px more from the current position!</a></div>);}});React.render(<Section/>,document.getElementById('example'));

Props/Options

activeClass class applied when element is reached
to Target to scroll to
containerId Container to listen for scroll events and to perform scrolling in
spy Make Link selected when scroll is at its targets position
hashSpy Update hash based on spy, containerId has to be set to scroll a specific element
smooth Animate the scrolling
offset Scroll additional px ( like padding )
duration time of the scroll animation - can be a number or a function (`function (scrollDistanceInPx) { return duration; }`), that allows more granular control at run-time
delay Wait x milliseconds before scroll
isDynamic In case the distance has to be recalculated - if you have content that expands etc.
onSetActive Invoke whenever link is being set to active
onSetInactive Invoke whenever link is lose the active status
ignoreCancelEvents Ignores events which cancel animated scrolling
horizontal Whether to scroll vertically (`false`) or horizontally (`true`) - default: `false`
spyThrottle Time of the spy throttle - can be a number

Full example

<LinkactiveClass="active"to="target"spy={true}smooth={true}hashSpy={true}offset={50}duration={500}delay={1000}isDynamic={true}onSetActive={this.handleSetActive}onSetInactive={this.handleSetInactive}ignoreCancelEvents={false}spyThrottle={500}> Your name </Link>

Scroll Methods

Scroll To Top

varScroll=require('react-scroll');varscroll=Scroll.animateScroll;scroll.scrollToTop(options);

Scroll To Bottom

varScroll=require('react-scroll');varscroll=Scroll.animateScroll;scroll.scrollToBottom(options);

Scroll To (position)

varScroll=require('react-scroll');varscroll=Scroll.animateScroll;scroll.scrollTo(100,options);

Scroll To (Element)

animateScroll.scrollTo(positionInPixels, props = {});

varScroll=require('react-scroll');varElement=Scroll.Element;varscroller=Scroll.scroller;<Elementname="myScrollToElement"></Element>// Somewhere else, even another filescroller.scrollTo('myScrollToElement',{duration: 1500,delay: 100,smooth: true,containerId: 'ContainerElementID',offset: 50,// Scrolls to element + 50 pixels down the page ... })

Scroll More (px)

varScroll=require('react-scroll');varscroll=Scroll.animateScroll;scroll.scrollMore(10,options);

Scroll events

begin - start of the scrolling

varScroll=require('react-scroll');varEvents=Scroll.Events;Events.scrollEvent.register('begin',function(to,element){console.log('begin',to,element);});

end - end of the scrolling/animation

Events.scrollEvent.register('end',function(to,element){console.log('end',to,element);});

Remove events

Events.scrollEvent.remove('begin');Events.scrollEvent.remove('end');

Create your own Link/Element

Simply just pass your component to one of the high order components (Element/Scroll)

varReact=require('react');varScroll=require('react-scroll');varScrollLink=Scroll.ScrollLink;varScrollElement=Scroll.ScrollElement;varElement=React.createClass({render: function(){return(<div{...this.props}ref={(el)=>{this.props.parentBindings.domNode=el;}}>{this.props.children}</div>);}});module.exports=ScrollElement(Element);varLink=React.createClass({render: function(){return(<a{...this.props}>{this.props.children}</a>);}});module.exports=ScrollLink(Link);

Scroll Animations

Add a custom easing animation to the smooth option. This prop will accept a Boolean if you want the default, or any of the animations listed below

scroller.scrollTo('myScrollToElement',{duration: 1500,delay: 100,smooth: 'easeInOutQuint',containerId: 'ContainerElementID', ... })

List of currently available animations:

A good visual reference can be found at easings.net

Changelog

Sours: https://www.npmjs.com/package/react-scroll
  1. Kevin cox picks
  2. Antique truck picture
  3. Confluence export html

React Scroll

React component for animating vertical scrolling

Install

$npminstallreact-scroll

Run

$npminstall$npmtest$npmstart

Examples

Checkout examples

Live example

Basic

Basic-Keydown

Container

With-hash

With-overflow

Code

Usage

// ES6 Importsimport*asScrollfrom'react-scroll';import{Link,Button,Element,Events,animateScrollasscroll,scrollSpy,scroller}from'react-scroll'// Or Access Link,Element,etc as followsletLink=Scroll.Link;letButton=Scroll.Button;letElement=Scroll.Element;letEvents=Scroll.Events;letscroll=Scroll.animateScroll;letscrollSpy=Scroll.scrollSpy;// ES5varReact=require('react');varScroll=require('react-scroll');varLink=Scroll.Link;varButton=Scroll.Button;varElement=Scroll.Element;varEvents=Scroll.Events;varscroll=Scroll.animateScroll;varscrollSpy=Scroll.scrollSpy;varSection=React.createClass({componentDidMount: function(){Events.scrollEvent.register('begin',function(to,element){console.log('begin',arguments);});Events.scrollEvent.register('end',function(to,element){console.log('end',arguments);});scrollSpy.update();},componentWillUnmount: function(){Events.scrollEvent.remove('begin');Events.scrollEvent.remove('end');},scrollToTop: function(){scroll.scrollToTop();},scrollToBottom: function(){scroll.scrollToBottom();},scrollTo: function(){scroll.scrollTo(100);},scrollMore: function(){scroll.scrollMore(100);},handleSetActive: function(to){console.log(to);},render: function(){return(<div><LinkactiveClass="active"to="test1"spy={true}smooth={true}offset={50}duration={500}onSetActive={this.handleSetActive}> Test 1 </Link><LinkactiveClass="active"to="test1"spy={true}smooth={true}offset={50}duration={500}delay={1000}> Test 2 (delay) </Link><LinkclassName="test6"to="anchor"spy={true}smooth={true}duration={500}> Test 6 (anchor) </Link><ButtonactiveClass="active"className="btn"type="submit"value="Test 2"to="test2"spy={true}smooth={true}offset={50}duration={500}> Test 2 </Button><Elementname="test1"className="element"> test 1 </Element><Elementname="test2"className="element"> test 2 </Element><divid="anchor"className="element"> test 6 (anchor) </div><Linkto="firstInsideContainer"containerId="containerElement"> Go to first element inside container </Link><Linkto="secondInsideContainer"containerId="containerElement"> Go to second element inside container </Link><divclassName="element"id="containerElement"><Elementname="firstInsideContainer"> first element inside container </Element><Elementname="secondInsideContainer"> second element inside container </Element></div><aonClick={this.scrollToTop}>To the top!</a><br/><aonClick={this.scrollToBottom}>To the bottom!</a><br/><aonClick={this.scrollTo}>Scroll to 100px from the top</a><br/><aonClick={this.scrollMore}>Scroll 100px more from the current position!</a></div>);}});React.render(<Section/>,document.getElementById('example'));

Props/Options

activeClass class applied when element is reached
to Target to scroll to
containerId Container to listen for scroll events and to perform scrolling in
spy Make Link selected when scroll is at its targets position
hashSpy Update hash based on spy, containerId has to be set to scroll a specific element
smooth Animate the scrolling
offset Scroll additional px ( like padding )
duration time of the scroll animation - can be a number or a function (`function (scrollDistanceInPx) { return duration; }`), that allows more granular control at run-time
delay Wait x milliseconds before scroll
isDynamic In case the distance has to be recalculated - if you have content that expands etc.
onSetActive Invoke whenever link is being set to active
onSetInactive Invoke whenever link is lose the active status
ignoreCancelEvents Ignores events which cancel animated scrolling
horizontal Whether to scroll vertically (`false`) or horizontally (`true`) - default: `false`
spyThrottle Time of the spy throttle - can be a number

Full example

<LinkactiveClass="active"to="target"spy={true}smooth={true}hashSpy={true}offset={50}duration={500}delay={1000}isDynamic={true}onSetActive={this.handleSetActive}onSetInactive={this.handleSetInactive}ignoreCancelEvents={false}spyThrottle={500}> Your name </Link>

Scroll Methods

Scroll To Top

varScroll=require('react-scroll');varscroll=Scroll.animateScroll;scroll.scrollToTop(options);

Scroll To Bottom

varScroll=require('react-scroll');varscroll=Scroll.animateScroll;scroll.scrollToBottom(options);

Scroll To (position)

varScroll=require('react-scroll');varscroll=Scroll.animateScroll;scroll.scrollTo(100,options);

Scroll To (Element)

animateScroll.scrollTo(positionInPixels, props = {});

varScroll=require('react-scroll');varElement=Scroll.Element;varscroller=Scroll.scroller;<Elementname="myScrollToElement"></Element>// Somewhere else, even another filescroller.scrollTo('myScrollToElement',{duration: 1500,delay: 100,smooth: true,containerId: 'ContainerElementID',offset: 50,// Scrolls to element + 50 pixels down the page ... })

Scroll More (px)

varScroll=require('react-scroll');varscroll=Scroll.animateScroll;scroll.scrollMore(10,options);

Scroll events

begin - start of the scrolling

varScroll=require('react-scroll');varEvents=Scroll.Events;Events.scrollEvent.register('begin',function(to,element){console.log('begin',to,element);});

end - end of the scrolling/animation

Events.scrollEvent.register('end',function(to,element){console.log('end',to,element);});

Remove events

Events.scrollEvent.remove('begin');Events.scrollEvent.remove('end');

Create your own Link/Element

Simply just pass your component to one of the high order components (Element/Scroll)

varReact=require('react');varScroll=require('react-scroll');varScrollLink=Scroll.ScrollLink;varScrollElement=Scroll.ScrollElement;varElement=React.createClass({render: function(){return(<div{...this.props}ref={(el)=>{this.props.parentBindings.domNode=el;}}>{this.props.children}</div>);}});module.exports=ScrollElement(Element);varLink=React.createClass({render: function(){return(<a{...this.props}>{this.props.children}</a>);}});module.exports=ScrollLink(Link);

Scroll Animations

Add a custom easing animation to the smooth option. This prop will accept a Boolean if you want the default, or any of the animations listed below

scroller.scrollTo('myScrollToElement',{duration: 1500,delay: 100,smooth: 'easeInOutQuint',containerId: 'ContainerElementID', ... })

List of currently available animations:

A good visual reference can be found at easings.net

Changelog

Sours: https://github.com/fisshy/react-scroll
51 ReactJS basics - Infinite scroll component

Build a Reusable Scroll List Component with Animated scrollTo in React

Intro

It is common in applications to have a scrollable list of content. Depending on other interactions you may want to programmatically scroll to a specific list item. This can occur throughout many areas in your application, and re-building this for everything is unnecessary.

Additionally we don't want our reusable component to add any additional markup. The reason being that some people have very specific styling and adding additional markup may effect that styling.

What are we building? Well something like this. Don't mind the ugly styling, this just a non-styled demo. We'll primarily focus on building this out as a reusable component.

Setup

We're going to start by setting a scrollable list. We have some random data containing images and a name.

This will require some CSS. Our CSS will have an class. This will just constrain our application to a specific width and center it.

The important class is the class. We have a height, and . Whenever the inner content of the div with grows beyond the visible height it will add a scrollbar. In our case anytime our content is more than it will add the scrollbar.

Our starting application code will just be a few divs, with our items being mapped over and rendering our items.

Making the ScrollView

To avoid adding additional markup we'll just return , and use . When using it will throw an error when attempting to pass in multiple children.

Because we'll use we'll need . They have since been deprecated from the core of React and moved into a separate package called .

So we'll need to run . Then import it into our file.

Now we'll setup our child context. We have to specify the type of data we are passing down and React will verify that the correct data types are being passed.

Now that we are specifying a context for our children to use. We will setup and functions to pass down on our object.

Our will take a and to a component that we can scroll to. Then our will be called to remove an element when an item is removed from a list.

Finally we need to setup to define the context for our child elements to get access to.

Now we're going to need to make a component to register itself with our .

Making our ScrollElement

Once again because we don't want to add additional markup we'll use the call. This will allow us to clone an element and add additional properties onto it.

In our case we need to add the prop. This will allow us to eventually get access to the DOM node so that we can scroll to it.

We use the callback ref style of ref because this will allow multiple refs to be used if there are multiple clone elements called, or if a ref is defined on the component.

Next up we need to grab the object we defined on context. We won't use , we need to use this time.

Now in our we will call our function with the ref and also which is defined by the application using the library we're building.

Finally when the component is unmounting we'll call with the name.

Scrolling

You may be moving from a implementation, and might want to be getting rid of a dependency. To avoid using or reimplementing the logic of an animated scroll we can use the library.scroll-into-view.

It has 0 dependencies besides to help polyfill for older browsers.

We will need to add the method onto our `ScrollView.

Because we are using we don't know if our child is a or if it's a custom component. Since it could be a custom component we need to use from to be able to get access to the actual DOM node.

Then we pass it into our and it will scroll to the element over and we set the so that it will scroll to the top of the element we are passing in.

Using Our Elements

We will wrap our with the class in our . We'll add a like so that we can get access to the function that we wrote.

Each of our items needs to be wrapped in our and then pass in a or any other identifying information that we can use to call our later.

To test out our demo we'll insert some buttons and setup a function to call on our ref.

As you can see here will call on our which will then call the on our component. This will then trigger our animated scroll.

Our app code looks like this.

What it looks like in use

Ending

This isn't robust but you can see how to use to pass information from a top level wrapping component to children component and build out a library. Using context means none of our implementation is being leaked to the application code.

Final Code

Code

Discord Logo

Code Daily Discord

Join our community and get help with React, React Native, and all web technologies. Even recommend tutorials, and content you want to see.

Join the community

Sours: https://codedaily.io/tutorials/Build-a-Reusable-Scroll-List-Component-with-Animated-scrollTo-in-React

Scrollable component react

npm

nextfunctiona function which must be called after reaching the bottom. It must trigger some sort of action which fetches the next data. The data is passed as to the component and the data should contain previous items too. e.g. Initial data = [1, 2, 3] and then next load of data should be [1, 2, 3, 4, 5, 6].hasMorebooleanit tells the component on whether to call function on reaching the bottom and shows an to the userchildrennode (list)the data items which you need to scroll.dataLengthnumberset the length of the data.This will unlock the subsequent calls to next.loadernodeyou can send a loader component to show while the component waits for the next load of data. e.g. or any fancy loader elementscrollThresholdnumber | stringA threshold value defining when will call . Default value is . It means the will be called when user comes below 80% of the total height. If you pass threshold in pixels (), will be called once you scroll at least (100% - scrollThreshold) pixels down.onScrollfunctiona function that will listen to the scroll event on the scrolling container. Note that the scroll event is throttled, so you may not receive as many events as you would expect.endMessagenodethis message is shown to the user when he has seen all the records which means he's at the bottom and is classNamestringadd any custom class you wantstyleobjectany style which you want to overrideheightnumberoptional, give only if you want to have a fixed height scrolling contentscrollableTargetnode or stringoptional, reference to a (parent) DOM element that is already providing overflow scrollbars to the component. You should provide the of the DOM node preferably.hasChildrenbool is by default assumed to be of type array and it's length is used to determine if loader needs to be shown or not, if your is not an array, specify this prop to tell if your items are 0 or more.pullDownToRefreshboolto enable Pull Down to Refresh featurepullDownToRefreshContentnodeany JSX that you want to show the user, releaseToRefreshContentnodeany JSX that you want to show the user, pullDownToRefreshThresholdnumberminimum distance the user needs to pull down to trigger the refresh, , a lower value may be needed to trigger the refresh depending your users browser.refreshFunctionfunctionthis function will be called, it should return the fresh data that you want to show the userinitialScrollYnumberset a scroll y position for the component to render with.inverseboolset infinite scroll on top
Sours: https://www.npmjs.com/package/react-infinite-scroll-component
Smooth scrolling in react using react-scroll package

Scroll

A collection of 74 posts

A simple react onscroll sticky Nav bar library
Navbar

A simple react onscroll sticky Nav bar library

A simple react onscroll sticky Nav bar library
04 October 2021
React hook to calculate the size of browser scrollbars
Scroll

React hook to calculate the size of browser scrollbars

React-Scrollbar-Size is a React hook designed to calculate the size of the user agent's horizontal and vertical scrollbars.
26 September 2021
A POC to replicate the native interaction behavior of iOS modal presentation with React Navigation
Navigator

A POC to replicate the native interaction behavior of iOS modal presentation with React Navigation

This is a POC to replicate the native interaction behavior of iOS modal presentation with React Navigation.
19 September 2021
React hooks and components for large data sets scrolling
Hooks

React hooks and components for large data sets scrolling

A set of hooks, components and utilities for scrolling large datasets.
08 August 2021
React hook to add draggability to scrollable content easily
Scroll

React hook to add draggability to scrollable content easily

React hook to add draggability to scrollable content easily.
19 June 2021
A thin react component wrapper bundled with scroll-into-view-if-needed
Scroll

A thin react component wrapper bundled with scroll-into-view-if-needed

A thin react component wrapper bundled with the fantastic scroll-into-view-if-needed ponyfill.
09 June 2021
React container that will auto scroll to bottom
Scroll

React container that will auto scroll to bottom

React container that will auto scroll to bottom or top if new content is added and viewport is at the bottom, similar to tail -f.
02 June 2021
A React component that scrolls to the top of a page
Scroll

A React component that scrolls to the top of a page

ScrollToTop is a React component that scrolls to the top of a page when the current location gets changed.
13 April 2021
A simple Sticky library for React
Sticky

A simple Sticky library for React

Sticky library for React.
21 March 2021
Easy to make scroll animation with ReactJS
Scroll

Easy to make scroll animation with ReactJS

Easy to make scroll animation with ReactJS.
30 January 2021
A react module for full page scroll
Fullscreen

A react module for full page scroll

A react module for full page scroll.
30 December 2020
React components for rendering large scrollable data
Scroll

React components for rendering large scrollable data

React components for rendering large scrollable data.
01 December 2020
React fixed table header position and auto scrollbar
Table

React fixed table header position and auto scrollbar

React fixed table header position and auto scrollbar.
22 September 2020
Scroll and Shader Effects in Three.js and React
Scroll

Scroll and Shader Effects in Three.js and React

Discover how to use react-three-fiber and combine some common techniques to create a Three.js powered layout with shader effects.
31 December 2019
Component that customizes the image and inserts shadow when scrolling exists
Scroll

Component that customizes the image and inserts shadow when scrolling exists

Component that customizes the image and inserts shadow when scrolling exists.
18 December 2019
React component which implements scrolling via holding the mouse button
Scroll

React component which implements scrolling via holding the mouse button

React component which implements scrolling via holding the mouse button or touch.
04 December 2019
The best React custom scrollbars component
Scroll

The best React custom scrollbars component

The best React custom scrollbars component.
05 November 2019
React component for listening to and acting on scroll/wheel/touchmove events
Scroll

React component for listening to and acting on scroll/wheel/touchmove events

React component for listening to and acting on scroll/wheel/touchmove events.
01 July 2019
React drag and drop framework with inbuilt virtualizing scrollbars
Scroll

React drag and drop framework with inbuilt virtualizing scrollbars

react-virtualized-dnd is a React-based, fully virtualized drag-and-drop framework, enabling the the cross over of great user interaction and great performance.
10 May 2019
React hook which gives a smooth scrolling function
Scroll

React hook which gives a smooth scrolling function

React hook which gives a smooth scrolling function.
06 May 2019
React/redux wrappers for auto-scrolling react-collapse components
Accordion

React/redux wrappers for auto-scrolling react-collapse components

Component wrappers for auto-scrolling collapsible elements - with smooth animations powered by react-motion and react-collapse.
18 April 2019
A simple React component that lets you listen for when scrolled to the bottom
Scroll

A simple React component that lets you listen for when scrolled to the bottom

A simple listener component that invokes a callback when the webpage is scrolled to the bottom.
10 March 2019
React library that tracks a users progress through a page as they scroll
Progress

React library that tracks a users progress through a page as they scroll

react-page-progress React library that tracks a users progress through a page as they scroll. View demo Download Source Install npm i react-page-progress OR yarn add react-page-progress Usage Props Props Type isRequired Example color
23 January 2019
A react wrapper for perfect-scrollbar
Scroll

A react wrapper for perfect-scrollbar

This is a wrapper to allow use perfect-scrollbar in React.
07 January 2019
A React navbar component based on react-scroll
Navbar

A React navbar component based on react-scroll

This Repo is not actively maintained! Please do not use in professional environment!
06 January 2019
A sticky view with scroll listener API for parallax style views
Scroll

A sticky view with scroll listener API for parallax style views

This is the contributor documentation for the react-stickyroll mono-repository.
08 December 2018
A react implementation of stickyroll
Scroll

A react implementation of stickyroll

Stickyroll is the successor of react-over-scroll.
01 December 2018
React component for sticky topbar that will hide when scrolling down
Scroll

React component for sticky topbar that will hide when scrolling down

SmartSticky is React component for sticky topbar that will hide when scrolling down and show when scrolling up.
22 November 2018
Create Fullscreen Scrolling Websites
Scroll

Create Fullscreen Scrolling Websites

This project is still in a very early stage. You shouldn't use this for production unless you really know what you're doing.
30 October 2018
React component for keeping components scrolled down
Scroll

React component for keeping components scrolled down

Keep your component, such as message boxes, scrolled down.
27 October 2018
React component to keep the scroll of the page and to restore it
Scroll

React component to keep the scroll of the page and to restore it

React component to keep the scroll of the page and to restore it if the user clicks on the back button of its browser.
27 October 2018
A scroll based slideshow with wings
Scroll

A scroll based slideshow with wings

OverScroll is a slide-show or content-slider, call it what you want.
26 October 2018
Scroll to a position in React
Scroll

Scroll to a position in React

React Scroll-To provides a Higher Order Component, and Render Props implementation.
18 October 2018
Scroll-anim anim component for react
Scroll

Scroll-anim anim component for react

React ScrollAnim Component.
09 October 2018
React component for scrolling zooming and highlighting code samples
Scroll

React component for scrolling zooming and highlighting code samples

React component for scrolling, zooming and highlighting code.
04 September 2018
Simple React component for smoothy full-page scolling
Scroll

Simple React component for smoothy full-page scolling

Simple React component for smoothy full-page scolling.
20 August 2018
Horizontal scrolling menu component for React
Scroll

Horizontal scrolling menu component for React

This is horizontal scrolling menu component for React. Menu component has adaptive width, just set width for parent container.
19 August 2018
Two decorators that inject window scroll position to your component's props
Scroll

Two decorators that inject window scroll position to your component's props

Two decorators (higher order components) that inject "window" scroll position, dimensions, orientation and breakpoint to your component's props.
15 July 2018
Prevent body scrolling on list bottom or top end
Scroll

Prevent body scrolling on list bottom or top end

prevent scrolling body, if list border reached, to get a better experience
26 June 2018
Simple custom scroll for React
Scroll

Simple custom scroll for React

This is little component for custom scroll in React. It is very customizable and flexible component. You can customization scrollbar.
24 June 2018
A React component to execute a function whenever you scroll to an element
Scroll

A React component to execute a function whenever you scroll to an element

A React component to execute a function whenever you scroll to an element. Works in all containers that can scroll, including the window.
19 June 2018
A React Component for parallax effect
Scroll

A React Component for parallax effect

A React Component for parallax effect.
19 June 2018
React component for creating on scroll effects aka
Scroll

React component for creating on scroll effects aka

Plx - React parallax component, lightweight and powerful.
10 June 2018
A React component for scroll to #hash links with smooth animations
Scroll

A React component for scroll to #hash links with smooth animations

A React component for scroll to #hash links with smooth animations. Scrollchor is a mix of Scroll and Anchor, a joke name for a useful component.
05 June 2018
A react implementation of fullpage.js
Scroll

A react implementation of fullpage.js

This is an implementation of fullpage.js in react. For the moment this is still in development and a lot of things can change.
20 May 2018
An awesome Infinite Scroll component in react
Infinite Scroll

An awesome Infinite Scroll component in react

A component to make all your infinite scrolling woes go away with just 4.15 kB!
17 May 2018
Customizable and flexible component for custom scroll in React
Scroll

Customizable and flexible component for custom scroll in React

This is little component for custom scroll in React. It is very customizable and flexible component. You can customization scrollbar.
16 May 2018
Sours: https://reactjsexample.com/tag/scroll/

You will also be interested:

ScrollView

Component that wraps platform ScrollView while providing integration with touch locking "responder" system.

Keep in mind that ScrollViews must have a bounded height in order to work, since they contain unbounded-height children into a bounded container (via a scroll interaction). In order to bound the height of a ScrollView, either set the height of the view directly (discouraged) or make sure all parent views have bounded height. Forgetting to transfer down the view stack can lead to errors here, which the element inspector makes quick to debug.

Doesn't yet support other contained responders from blocking this scroll view from becoming the responder.

vs - which one to use?

renders all its react child components at once, but this has a performance downside.

Imagine you have a very long list of items you want to display, maybe several screens worth of content. Creating JS components and native views for everything all at once, much of which may not even be shown, will contribute to slow rendering and increased memory usage.

This is where comes into play. renders items lazily, when they are about to appear, and removes items that scroll way off screen to save memory and processing time.

is also handy if you want to render separators between your items, multiple columns, infinite scroll loading, or any number of other features it supports out of the box.

Example#


Props#

View Props#

Inherits View Props.


#

A React Component that will be used to render sticky headers, should be used together with . You may need to set this component if your sticky header uses custom transforms, for example, when you want your list to have an animated and hidable header. If component have not been provided, the default component will be used.


iOS

#

When true, the scroll view bounces horizontally when it reaches the end even if the content is smaller than the scroll view itself.

TypeDefault
bool when
otherwise

iOS

#

When true, the scroll view bounces vertically when it reaches the end even if the content is smaller than the scroll view itself.

TypeDefault
bool when
otherwise

iOS

#

Controls whether iOS should automatically adjust the content inset for scroll views that are placed behind a navigation bar or tab bar/toolbar.


iOS

#

Controls whether iOS should automatically adjust the scroll indicator insets. See Apple's documentation on the property.


iOS

#

When true, the scroll view bounces when it reaches the end of the content if the content is larger than the scroll view along the axis of the scroll direction. When , it disables all bouncing even if the props are .


iOS

#

When , gestures can drive zoom past min/max and the zoom will animate to the min/max value at gesture end, otherwise the zoom will not exceed the limits.


iOS

#

When , once tracking starts, won't try to drag if the touch moves.


iOS

#

When , the scroll view automatically centers the content when the content is smaller than the scroll view bounds; when the content is larger than the scroll view, this property has no effect.


#

These styles will be applied to the scroll view content container which wraps all of the child views. Example:


iOS

#

The amount by which the scroll view content is inset from the edges of the scroll view.

TypeDefault
object: {top: number, left: number, bottom: number, right: number}

iOS

#

This property specifies how the safe area insets are used to modify the content area of the scroll view. Available on iOS 11 and later.

TypeDefault
enum(, , , )

#

Used to manually set the starting scroll offset.

TypeDefault
Point

#

A floating-point number that determines how quickly the scroll view decelerates after the user lifts their finger. You may also use string shortcuts and which match the underlying iOS settings for and respectively.

  • 0.998 on iOS, 0.985 on Android.
  • , 0.99 on iOS, 0.9 on Android.
TypeDefault
enum(, ), number

iOS

#

When true, the ScrollView will try to lock to only vertical or horizontal scrolling while dragging.


#

When true, the scroll view stops on the next index (in relation to scroll position at release) regardless of how fast the gesture is. This can be used for pagination when the page is less than the width of the horizontal ScrollView or the height of the vertical ScrollView.


#

When true, the default JS pan responder on the ScrollView is disabled, and full control over touches inside the ScrollView is left to its child components. This is particularly useful if is enabled, since it does not follow typical touch patterns. Do not use this on regular ScrollView use cases without as it may cause unexpected touches to occur while scrolling.


Android

#

Sometimes a scrollview takes up more space than its content fills. When this is the case, this prop will fill the rest of the scrollview with a color to avoid setting a background and creating unnecessary overdraw. This is an advanced optimization that is not needed in the general case.


Android

#

Fades out the edges of the the scroll content.

If the value is greater than , the fading edges will be set accordingly to the current scroll direction and position, indicating if there is more content to show.


#

When , the scroll view's children are arranged horizontally in a row instead of vertically in a column.


iOS

#

The style of the scroll indicators.

  • same as .
  • , scroll indicator is . This style is good against a light background.
  • , scroll indicator is . This style is good against a dark background.
TypeDefault
enum(, , )

#

If sticky headers should stick at the bottom instead of the top of the ScrollView. This is usually used with inverted ScrollViews.


#

Determines whether the keyboard gets dismissed in response to a drag.

  • , drags do not dismiss the keyboard.
  • , the keyboard is dismissed when a drag begins.

iOS Only

  • , the keyboard is dismissed interactively with the drag and moves in synchrony with the touch, dragging upwards cancels the dismissal. On Android this is not supported and it will have the same behavior as .
TypeDefault
enum(, )

Android


enum(, , )

iOS


#

Determines when the keyboard should stay visible after a tap.

  • tapping outside of the focused text input when the keyboard is up dismisses the keyboard. When this happens, children won't receive the tap.
  • , the keyboard will not dismiss automatically, and the scroll view will not catch taps, but children of the scroll view can catch taps.
  • , the keyboard will not dismiss automatically when the tap was handled by children of the scroll view (or captured by an ancestor).
  • , deprecated, use instead
  • , deprecated, use instead
TypeDefault
enum(, , , , )

iOS

#

When set, the scroll view will adjust the scroll position so that the first child that is currently visible and at or beyond will not change position. This is useful for lists that are loading content in both directions, e.g. a chat thread, where new messages coming in might otherwise cause the scroll position to jump. A value of 0 is common, but other values such as 1 can be used to skip loading spinners or other content that should not maintain position.

The optional can be used to make the content automatically scroll to the top after making the adjustment if the user was within the threshold of the top before the adjustment was made. This is also useful for chat-like applications where you want to see new messages scroll into place, but not if the user has scrolled up a ways and it would be disruptive to scroll a bunch.

Caveat 1: Reordering elements in the scrollview with this enabled will probably cause jumpiness and jank. It can be fixed, but there are currently no plans to do so. For now, don't re-order the content of any ScrollViews or Lists that use this feature.

Caveat 2: This uses and in native code to compute visibility. Occlusion, transforms, and other complexity won't be taken into account as to whether content is "visible" or not.

Type
object: { minIndexForVisible: number, autoscrollToTopThreshold: number }

iOS

#

The maximum allowed zoom scale.


iOS

#

The minimum allowed zoom scale.


Android

#

Enables nested scrolling for Android API level 21+.


#

Called when scrollable content view of the ScrollView changes.

Handler function is passed the content width and content height as parameters:

It's implemented using onLayout handler attached to the content container which this ScrollView renders.


#

Called when the momentum scroll starts (scroll which occurs as the ScrollView starts gliding).


#

Called when the momentum scroll ends (scroll which occurs as the ScrollView glides to a stop).


#

Fires at most once per frame during scrolling. The frequency of the events can be controlled using the prop. The event has the following shape (all values are numbers):


#

Called when the user begins to drag the scroll view.


#

Called when the user stops dragging the scroll view and it either stops or begins to glide.


iOS

#

Fires when the scroll view scrolls to top after the status bar has been tapped.


Android

#

Used to override default value of overScroll mode.

Possible values:

  • - Allow a user to over-scroll this view only if the content is large enough to meaningfully scroll.
  • - Always allow a user to over-scroll this view.
  • - Never allow a user to over-scroll this view.
TypeDefault
enum(, , )

#

When true, the scroll view stops on multiples of the scroll view's size when scrolling. This can be used for horizontal pagination.

Note: Vertical pagination is not supported on Android.


Android

#

Causes the scrollbars not to turn transparent when they are not in use.


iOS

#

When true, ScrollView allows use of pinch gestures to zoom in and out.


#

A RefreshControl component, used to provide pull-to-refresh functionality for the ScrollView. Only works for vertical ScrollViews ( prop must be ).

See RefreshControl.


#

Experimental: When , offscreen child views (whose value is ) are removed from their native backing superview when offscreen. This can improve scrolling performance on long lists.


#

When false, the view cannot be scrolled via touch interaction.

Note that the view can always be scrolled by calling .


iOS

#

This controls how often the scroll event will be fired while scrolling (as a time interval in ms). A lower number yields better accuracy for code that is tracking the scroll position, but can lead to scroll performance problems due to the volume of information being sent over the bridge. You will not notice a difference between values set between 1-16 as the JS run loop is synced to the screen refresh rate. If you do not need precise scroll position tracking, set this value higher to limit the information being sent across the bridge. The default value is , which results in the scroll event being sent only once each time the view is scrolled.


iOS

#

The amount by which the scroll view indicators are inset from the edges of the scroll view. This should normally be set to the same value as the .

TypeDefault
object: {top: number, left: number, bottom: number, right: number}

Android

#

Tag used to log scroll performance on this scroll view. Will force momentum events to be turned on (see sendMomentumEvents). This doesn't do anything out of the box and you need to implement a custom native FpsListener for it to be useful.


iOS

#

When , the scroll view can be programmatically scrolled beyond its content size.


iOS

#

When , the scroll view scrolls to top when the status bar is tapped.


#

When , shows a horizontal scroll indicator.


#

When , shows a vertical scroll indicator.


iOS

#

When is set, will define the relationship of the snapping to the scroll view.

Possible values:

  • will align the snap at the left (horizontal) or top (vertical).
  • will align the snap in the center.
  • will align the snap at the right (horizontal) or bottom (vertical).
TypeDefault
enum(, , )

#

Use in conjunction with . By default, the end of the list counts as a snap offset. Set to false to disable this behavior and allow the list to scroll freely between its end and the last offset.


#

When set, causes the scroll view to stop at multiples of the value of . This can be used for paginating through children that have lengths smaller than the scroll view. Typically used in combination with and . Overrides less configurable prop.


#

When set, causes the scroll view to stop at the defined offsets. This can be used for paginating through variously sized children that have lengths smaller than the scroll view. Typically used in combination with . Overrides less configurable and props.


#

Use in conjunction with . By default, the beginning of the list counts as a snap offset. Set to to disable this behavior and allow the list to scroll freely between its start and the first offset.


#

When set to , sticky header will be hidden when scrolling down the list, and it will dock at the top of the list when scrolling up.


#

An array of child indices determining which children get docked to the top of the screen when scrolling. For example, passing will cause the first child to be fixed to the top of the scroll view. You can also use like [x,y,z] to make multiple items sticky when they are at the top. This property is not supported in conjunction with .


iOS

#

The current scale of the scroll view content.


Methods#

#

Displays the scroll indicators momentarily.


#

Scrolls to a given x, y offset, either immediately, with a smooth animation.

Example:

Note: The weird function signature is due to the fact that, for historical reasons, the function also accepts separate arguments as an alternative to the options object. This is deprecated due to ambiguity (y before x), and SHOULD NOT BE USED.


#

If this is a vertical ScrollView scrolls to the bottom. If this is a horizontal ScrollView scrolls to the right.

Use for smooth animated scrolling, for immediate scrolling. For Android, you may specify a duration, e.g. for a controlled duration scroll. If no options are passed, defaults to .

Sours: https://reactnative.dev/docs/scrollview


630 631 632 633 634