0.2.1 • Published 4 years ago

autoscroll v0.2.1

Weekly downloads
62
License
MIT
Repository
github
Last release
4 years ago

autoscroll

A utility for auto-scroll when trigger location of event (i.e. mouse event) almost reach boundary.

NPM

Installation

  1. Install the latest version of autoscroll:
  npm install --save autoscroll
  1. At this point you can import autoscroll:
import autoScroll from 'autoscroll';

Example

import React, { PureComponent } from 'react';
import autoScroll from 'autoscroll';

class Example extends PureComponent {
    refContent = (content) => {
        this.content = content;
    }

    actions = {
        onMouseMove: (e) => {
            // Start auto scrolling
            autoScroll.run(e, this.content);
        },
        onMouseOut: (e) => {
            // Stop auto scrolling if any
            autoScroll.end();
        }
    };

    render() {
        return (
            <div
                style={{
                    height: 500,
                    overflow: 'auto'
                }}
                ref={this.refContent}
                onMouseMove={this.actions.onMouseMove}
                onMouseOut={this.actions.onMouseOut}
            >
                <div
                    style={{
                        height: 1000,
                        backgroundColor: 'yellow'
                    }}
                />
            </div>
        );
    }
}

export default Example;

License

MIT

0.2.1

4 years ago

0.1.0

6 years ago