0.1.1 • Published 4 years ago

react-view-tracker v0.1.1

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

React View Tracker

npm package Module formats

Simple react component that watch element when enters or leaves the browser viewport.

Demo

Installation

Add react-view-tracker dependency

yarn add react-view-tracker
npm install react-view-tracker --save

Usage

import ViewTracker from 'react-view-tracker'
<ViewTracker
  onShow={(entry)=> {console.log(entry)})}
>
  <Content />
</ViewTracker>

Options

NameTypeDefaultRequiredDescription
onShowFunctionnullfalseWhen element visible in the view port this function will be called with entry.
onHideFunctionnullfalseWhen element visible then not visible in the view port this function will be called with entry
onStartObservingFunctionnullfalseWhen component did load it will start observing and call this function with container element
onStopObservingFunctionnullfalseWhen component un mount it will stop observing and call this function with container element
setRootContainerFunctionnullfalseThe Function should return Element that is used as the viewport for checking visibility of the target.
oncebooleanfalsefalseOnly trigger this method once
visiblePercentagenumber | number[]1falseNumber between 0 and 1 indicating the percentage that should be visible before triggering. Can also be an array of numbers, to create multiple trigger points.
offsetobject{left: 0, right: 0, top: 0, bottom: 0}falseMargin around the root.

License

This project is licensed under the MIT License - see the LICENCE.md file for details