react viewable
A react wrapper component that renders it's children only once the component is in view. Takes several optional props for timing customization.
See it in action here
Props
once : PropTypesboolreactionTime : PropTypesnumberbuffer : PropTypesnumberdelay : PropTypesnumberchildren : PropTypesnodeonViewEnter : PropTypesfunconViewLeave : PropTypesfunc // animation/style propsfade : PropTypesboolfadeDir : PropTypes
bool
optional
once false
default Whether the children only come into view once - if false, the children will animate out as soon as they are off screen, and then re-animate in next time they are on screen
number
optional
reactionTime 500
default How often the wrapper checks to see whether it's in the viewport in ms
number
optional
buffer 100
default The amount of pixels the wrapper allows to be in view, a larger number will start the transition before the element is in the viewport
number
optional
delay 500
default The time in milliseconds before which the transition starts once the component is in the viewport
bool
optional
fade true
default Whether the component fades into view with a transition
string
optional
fadeDir left
default The direction the component fades in from, can be top
, bottom
, left
or right
func
optional
onViewEnter A function that is called every time the component transitions from out of view to into view. Is passed the html element
func
optional
onViewLeave A function that is called every time the component transitions from into view to out of view. Is passed the html element
node
optional
children The content to render
Usage
npm install react-viewable
Here is an example integration:
; const MyApp = { return <Viewable once=true reactionTime=500 buffer=100 delay=500 onViewEnter= console onViewLeave= console fade=true fadeDir="left" > <MyComponent /> </Viewable> } ;
Development
- clone repo &&
npm install
- Development server
npm start
. - Build
npm run build
;