Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add percentage option for partial visibility #152

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

chrisvoll
Copy link

Hello! This change introduces a new prop, minTopPercent, which allows you to trigger a visibility change when a certain percent of the child component is visible. Our use case is that we have elements with dynamic heights, where we're interested in detecting if they're 50% visible, rather than checking for a fixed pixel value.

For example, to check if a component is 80% visible, you could use:

<VisibilitySensor
  minTopPercent={0.8}
  onChange={onChange}
  partialVisibility
>
  {child}
</VisibilitySensor>

If this is merged, it would close #125

thanks!

@@ -1,14 +1,12 @@
React Visibility Sensor
====
# React Visibility Sensor
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These markdown changes came from the prettier commit hook. I noticed that the commit hook wasn't covering the .jsx test file, so I updated it to include that

@vajkri
Copy link

vajkri commented Apr 10, 2019

Is this ready to be merged in @joshwnj? This'd be really neat feature to have :)

@Maxenboy
Copy link

is this stale? This would be awesome to have!!

@chrisvoll
Copy link
Author

@Maxenboy I haven't heard anything, but my team ended up forking the library, and we plan to swap it out with intersection observers, which have support for percentage thresholds built in.

@ezeikel
Copy link

ezeikel commented Feb 22, 2021

Just spent 30 minutes trying to implement this before realising it hasn't been merged yet!

I just did this until this gets merged in:

minTopValue={elementsHeightViaRef * 0.8}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Partial visibility in percentage
4 participants