diff --git a/README.md b/README.md index 8d3ec6b..be9b95e 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,7 @@ Props ---- - `onChange`: callback for whenever the element changes from being within the window viewport or not. Function is called with 1 argument `(isVisible: boolean)` +- `onCheck`: callback for whenever the element being checked if it is within the window viewport or not. Function is called with 1 argument `(isVisible: boolean)` after the check is done. - Same as `onChange` but called even if the visibility hasn't changed. - `active`: (default `true`) boolean flag for enabling / disabling the sensor. When `active !== true` the sensor will not fire the `onChange` callback. - `partialVisibility`: (default `false`) consider element visible if only part of it is visible. Also possible values are - 'top', 'right', 'bottom', 'left' - in case it's needed to detect when one of these become visible explicitly. - `offset`: (default `{}`) with offset you can define amount of px from one side when the visibility should already change. So in example setting `offset={{top:10}}` means that the visibility changes hidden when there is less than 10px to top of the viewport. Offset works along with `partialVisibility` diff --git a/visibility-sensor.js b/visibility-sensor.js index 067b3c4..3de071f 100644 --- a/visibility-sensor.js +++ b/visibility-sensor.js @@ -38,6 +38,7 @@ export default class VisibilitySensor extends React.Component { static propTypes = { onChange: PropTypes.func, + onCheck: PropTypes.func, active: PropTypes.bool, partialVisibility: PropTypes.oneOfType([ PropTypes.bool, @@ -321,6 +322,7 @@ export default class VisibilitySensor extends React.Component { if (this.props.onChange) this.props.onChange(isVisible); } + if (this.props.onCheck) this.props.onCheck(isVisible); return state; };