# react-scroll-to-component Smooth srolls to react component via reference ## Install #### With npm ```sh npm install react-scroll-to-component --save ``` #### With Yarn ```sh yarn add react-scroll-to-component ``` ## `scrollToComponent(ref, )` ##### Valid options: > ###### offset : *number* > Add an offset to the final position. if > 0 then page is moved to the bottom otherwise the page is moved to the top. ###### align : *string* > Alignment of the element. Can be one of `'top'`, `'middle'` or `'bottom'`. Defaulting to `'middle'`. ###### ease : *string* > Easing function defaulting to "out-circ" (view [ease](https://github.com/component/ease) for more) ###### duration : *number* > Animation duration defaulting to `1000` ## Example ```js import scrollToComponent from 'react-scroll-to-component'; // without options scrollToComponent(this.refs.name); //with options scrollToComponent(this.refs.name, { offset: 1000, align: 'top', duration: 1500 }); ``` ## [Demo](https://flyingant.github.io/react-scroll-to-component/) ```js import React, { Component } from 'react'; import './App.css'; import scrollToComponent from 'react-scroll-to-component'; class App extends React.Component { componentDidMount() { scrollToComponent(this.Blue, { offset: 0, align: 'middle', duration: 500, ease:'inCirc'}); } render() { return (
{ this.Violet = section; }}>Violet
{ this.Indigo = section; }}>Indigo
{ this.Blue = section; }}>Blue
{ this.Green = section; }}>Green
{ this.Yellow = section; }}>Yellow
{ this.Orange = section; }}>Orange
{ this.Red = section; }}>Red
Inspired By Hope with Love and Peace
) } } export default App; ``` # License MIT