artyom.poteshkin98
artyom.poteshkin98

Reputation: 129

ReactJS: How to get height of visible part of element when scroll

How can I fetch the visible height of div when it scrolled (Visited your profile in October):

enter image description here

The full div height - 127px. I've tried to dancing with getBoundingClientRect(), but nothing has changed.

<div id="root">
  ...
  <div id="statisticsContainer">
    <p>
      <Icon/>
      Visited you profile in October
    </p>
    <div id="mainValueContainer">
      <p>0</p>
    </div>
  </div>
</div>

Upvotes: 1

Views: 864

Answers (1)

Abdellah Hariti
Abdellah Hariti

Reputation: 707

  1. You can use the IntersectoinObserver to detect the element coming into view, play around with the threshold to get it detected when it's barely in view.

  2. Element.offsetHeight gives you the actual height

Upvotes: 1

Related Questions