Skip to content

Commit 311d413

Browse files
authored
Update README.md
1 parent fb55307 commit 311d413

File tree

1 file changed

+5
-83
lines changed

1 file changed

+5
-83
lines changed

README.md

+5-83
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,22 @@
1-
# react-scroll-to-component
2-
Smooth srolls to react component via reference
1+
# react-scroll-to-component-ssr
2+
This repo is aimed to avoid the error from https://github.com/flyingant/react-scroll-to-component/issues/8 and https://github.com/component/scroll-to/issues/9
33

44
## Install
55

66
#### With npm
77

88
```sh
9-
npm install react-scroll-to-component --save
9+
npm install react-scroll-to-component-ssr --save
1010
```
1111

1212
#### With Yarn
1313

1414

1515
```sh
16-
yarn add react-scroll-to-component
17-
```
18-
19-
## `scrollToComponent(ref, <options>)`
20-
21-
##### Valid options:
22-
23-
>
24-
###### offset : *number*
25-
> Add an offset to the final position. if > 0 then page is moved to the bottom otherwise the page is moved to the top.
26-
###### align : *string*
27-
> Alignment of the element. Can be one of `'top'`, `'middle'` or `'bottom'`. Defaulting to `'middle'`.
28-
###### ease : *string*
29-
> Easing function defaulting to "out-circ" (view [ease](https://github.com/component/ease) for more)
30-
###### duration : *number*
31-
> Animation duration defaulting to `1000`
32-
33-
## Example
34-
```js
35-
import scrollToComponent from 'react-scroll-to-component';
36-
37-
// without options
38-
scrollToComponent(this.refs.name);
39-
40-
//with options
41-
scrollToComponent(this.refs.name, {
42-
offset: 1000,
43-
align: 'top',
44-
duration: 1500
45-
});
46-
```
47-
## [Demo](https://flyingant.github.io/react-scroll-to-component/)
48-
49-
```js
50-
import React, { Component } from 'react';
51-
import './App.css';
52-
import scrollToComponent from 'react-scroll-to-component';
53-
54-
class App extends React.Component {
55-
56-
constructor(props) {
57-
super(props);
58-
this.scrollToTopWithCallback = this.scrollToTopWithCallback.bind(this)
59-
}
60-
61-
componentDidMount() {
62-
scrollToComponent(this.Blue, { offset: 0, align: 'middle', duration: 500, ease:'inCirc'});
63-
}
64-
65-
scrollToTopWithCallback() {
66-
let scroller = scrollToComponent(this.Violet, { offset: 0, align: 'top', duration: 1500});
67-
scroller.on('end', () => console.log('Scrolling end!') );
68-
}
69-
70-
render() {
71-
return (
72-
<div className='main'>
73-
<div className='button_group'>
74-
<button onClick={this.scrollToTopWithCallback}>Go To Violet</button>
75-
<button onClick={() => scrollToComponent(this.Indigo, { offset: 0, align: 'bottom', duration: 500, ease:'inExpo'})}>Go To Indigo</button>
76-
<button onClick={() => scrollToComponent(this.Blue, { offset: -200, align: 'middle', duration: 1500, ease:'inCirc'})}>Go To Blue</button>
77-
<button onClick={() => scrollToComponent(this.Green, { offset: 0, align: 'middle', duration: 500, ease:'inExpo'})}>Go To Green</button>
78-
<button onClick={() => scrollToComponent(this.Yellow, { offset: 0, align: 'top', duration: 1500, ease:'inCirc'})}>Go To Yellow</button>
79-
<button onClick={() => scrollToComponent(this.Orange, { offset: 0, align: 'top', duration: 500, ease:'inCirc'})}>Go To Orange</button>
80-
<button onClick={() => scrollToComponent(this.Red, { offset: 0, align: 'top', duration: 500})}>Go To Red</button>
81-
</div>
82-
<section className='violet' ref={(section) => { this.Violet = section; }}>Violet</section>
83-
<section className='indigo' ref={(section) => { this.Indigo = section; }}>Indigo</section>
84-
<section className='blue' ref={(section) => { this.Blue = section; }}>Blue</section>
85-
<section className='green' ref={(section) => { this.Green = section; }}>Green</section>
86-
<section className='yellow' ref={(section) => { this.Yellow = section; }}>Yellow</section>
87-
<section className='orange' ref={(section) => { this.Orange = section; }}>Orange</section>
88-
<section className='red' ref={(section) => { this.Red = section; }}>Red</section>
89-
<b>Inspired By <a href="https://hopechen1028.github.io/hopechen.me/" target="_blank">Hope</a> with Love and Peace</b>
90-
</div>
91-
)
92-
}
93-
}
94-
95-
export default App;
16+
yarn add react-scroll-to-component-ssr
9617
```
9718

19+
For usage and details, please refer to https://github.com/flyingant/react-scroll-to-component
9820

9921
# License
10022

0 commit comments

Comments
 (0)