);
}
});
React.render(
,
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
```js
Your name
```
### Scroll Methods
> Scroll To Top
```js
var Scroll = require('react-scroll');
var scroll = Scroll.animateScroll;
scroll.scrollToTop(options);
```
> Scroll To Bottom
```js
var Scroll = require('react-scroll');
var scroll = Scroll.animateScroll;
scroll.scrollToBottom(options);
```
> Scroll To (position)
```js
var Scroll = require('react-scroll');
var scroll = Scroll.animateScroll;
scroll.scrollTo(100, options);
```
> Scroll To (Element)
animateScroll.scrollTo(positionInPixels, props = {});
```js
var Scroll = require('react-scroll');
var Element = Scroll.Element;
var scroller = Scroll.scroller;
// Somewhere else, even another file
scroller.scrollTo('myScrollToElement', {
duration: 1500,
delay: 100,
smooth: true,
containerId: 'ContainerElementID',
offset: 50, // Scrolls to element + 50 pixels down the page
...
})
```
> Scroll More (px)
```js
var Scroll = require('react-scroll');
var scroll = Scroll.animateScroll;
scroll.scrollMore(10, options);
```
### Scroll events
> begin - start of the scrolling
```js
var Scroll = require('react-scroll');
var Events = Scroll.Events;
Events.scrollEvent.register('begin', function(to, element) {
console.log('begin', to, element);
});
```
> end - end of the scrolling/animation
```js
Events.scrollEvent.register('end', function(to, element) {
console.log('end', to, element);
});
```
> Remove events
```js
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)
```js
var React = require('react');
var Scroll = require('react-scroll');
var ScrollLink = Scroll.ScrollLink;
var ScrollElement = Scroll.ScrollElement;
var Element = React.createClass({
render: function () {
return (
);
}
});
module.exports = ScrollElement(Element);
var Link = React.createClass({
render: function () {
return (
{this.props.children}
);
}
});
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
```js
scroller.scrollTo('myScrollToElement', {
duration: 1500,
delay: 100,
smooth: 'easeInOutQuint',
containerId: 'ContainerElementID',
...
})
```
> List of currently available animations:
```
linear
- no easing, no acceleration.
easeInQuad
- accelerating from zero velocity.
easeOutQuad
- decelerating to zero velocity.
easeInOutQuad
- acceleration until halfway, then deceleration.
easeInCubic
- accelerating from zero velocity.
easeOutCubic
- decelerating to zero velocity.
easeInOutCubic
- acceleration until halfway, then deceleration.
easeInQuart
- accelerating from zero velocity.
easeOutQuart
- decelerating to zero velocity.
easeInOutQuart
- acceleration until halfway, then deceleration.
easeInQuint
- accelerating from zero velocity.
easeOutQuint
- decelerating to zero velocity.
easeInOutQuint
- acceleration until halfway, then deceleration.
```
A good visual reference can be found at [easings.net](http://easings.net/)
#### Changelog
- [See the CHANGELOG](./CHANGELOG.md)