2.1.0 • Published 5 years ago

react-intersection-visible v2.1.0

Weekly downloads
1,217
License
MIT
Repository
github
Last release
5 years ago

react-intersection-visible

HOC-wrapper Component that helps you track when an element enters in the viewport. It uses the new IntersectionObserver API with polyfill fallback

Demo

Build Status Greenkeeper badge

How to use

  1. Import IntersectionVisible hoc component
  2. Wrap your main component with the IntersectionVisible
  3. Provide the options and callbacks you want

Example

import React, { Component }   from 'react';
import ReactDOM               from 'react-dom';
import IntersectionVisible    from 'react-intersection-visible';

class YourComponent extends Component
{

    onHide( entries )
    {
        // do something
    }

    onShow( entries )
    {
        // do something
    }

    onIntersect( entries )
    {
        // do something
    }

    render(){
        return (<IntersectionVisible onIntersect={ e => this.onIntersect( e ) }
                                     onHide={ e => this.onHide( e ) }
                                     onShow={ e => this.onShow( e ) }>
                    <div>
                        blah blah blah  blah blah blah  blah blah blah  blah blah
                          blah blah blah  blah blah blah  blah blah blah
                    </div>
                </IntersectionVisible>);
    }
}

Options:

NameDescription
onIntersectFunction that is called when the visibility status of the element change
onHideFunction that is called when the element becomes invisible
onShowFunction that is called when the element becomes visible
optionsObject, with the extras options supported by the IntersectionObserver API (root, rootMargin, threshold)

More about the options here

Contribute

Any pull-request is more than welcome :boom: :smile:

License

MIT

2.1.0

5 years ago

2.0.6

6 years ago

2.0.5

6 years ago

2.0.4

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.1.2

6 years ago

1.1.0

7 years ago

1.0.0

8 years ago