GithubHelp home page GithubHelp logo

kovenliao / react-scroll-to Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ganderzz/react-scroll-to

0.0 2.0 0.0 381 KB

Scroll to a position in React

License: MIT License

JavaScript 100.00%

react-scroll-to's Introduction

๐Ÿ‘Ÿ React Scroll-To

CircleCI Coverage Status All Contributors PRs Welcome

A React component that makes scrolling easy.

React Scroll-To provides a Higher Order Component, and Render Props implementation.

Install

npm: npm install react-scroll-to --save

yarn: yarn add react-scroll-to

API

Render Props:

// Scroll to position (0, 500) in the browser window
import React, { Component } from "react";
import { ScrollTo } from "react-scroll-to";

export default class MyComponent extends Component {
    render() {
        return (
            <ScrollTo>
                {
                    (scroll) => (
                        <a onClick={() => scroll(0, 500)}>
                            Scroll to Bottom
                        </a>
                    )
                }
            </ScrollTo>
        );
    }
}
// Scroll to position (0, 500) within a provided container
import React, { Component } from "react";
import { ScrollTo, ScrollArea } from "react-scroll-to";

export default class MyComponent extends Component {
    render() {
        return (
            <ScrollTo>
                {
                  (scroll) => (
                      <ScrollArea style={{ height: 1000 }}>
                        <button onClick={() => scroll(0, 500)}>
                          Scroll within this container
                        </button>
                      </ScrollArea>
                  )
                }
            </ScrollTo>
        );
    }
}

Higher Order Component:

// Scroll to position (0, 500) within the browser window
import React from "react";
import { ScrollToHOC } from "react-scroll-to";

export default ScrollToHOC(function(props) {
    return (
        <a onClick={() => props.scroll(0, 500)}>
            Scroll to Bottom
        </a>
    );
})
// Scroll to position (0, 500) within a provided container
import React from "react";
import { ScrollToHOC, ScrollArea } from "react-scroll-to";

export default ScrollToHOC(function(props) {
    return (
        <ScrollArea style={{ height: 1000 }}>
            <a onClick={() => props.scroll(0, 500)}>
                Scroll to Bottom
            </a>
        </ScrollArea>
    );
})

Example

Check out this example on CodeSandbox.

Contributors

Thanks goes to these wonderful people (emoji key):


Dylan Paulus

๐Ÿ’ป ๐Ÿ“–

Anthony Ng

๐Ÿ’ป ๐Ÿ“–

UmenR

๐Ÿ’ป

This project follows the all-contributors specification. Contributions of any kind welcome!

react-scroll-to's People

Contributors

ganderzz avatar newyork-anthonyng avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.