0.1.2 • Published 8 years ago

react-scroll-area v0.1.2

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

React Scroll Area

npm install react-scroll-area

A React component that enables you to programmatically scroll to child components within it.

Example Usage

import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import ScrollArea from 'react-scroll-area';

class MyComponent extends Component {

  componentDidMount() {
    const scrollarea = ReactDOM.findDOMNode(this.refs.scrollarea);

    setTimeout(() => {
      scrollarea.scrollTo(this.refs.first_target);
    }, 3000);

    setTimeout(() => {
      scrollarea.scrollTo(this.refs.second_target, {
        offsetTop: -100,
        offsetLeft: 0,
        duration: 2000,
        delay: 500,
        tick: 50,
      });
    }, 6000);
  }

  render() {
    return (
      <ScrollArea style={{width: 400, height: 400}} ref='scrollarea'>
        <h2 ref="first_target" style={{marginBottom: 500}}>First Target</h2>
        <h2 ref="second_target">Second Target</h2>
      </ScrollArea>
    );
  }
}

Options

Passed as second argument to scrollTo method.

Prop NameDescriptionDefault Value
offsetTopdesired vertical offset of scroll container from target at end of scroll0
offsetLeftdesired horizontal offset of scroll container from target at end of scroll0
durationduration of scroll200
delaydelay before starting to scroll0
tickperiod between each tick of scroll animation30

License

MIT