You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
817 B

  1. // Get the bounding client rect from an IntersectionObserver entry.
  2. // This is to work around a bug in Chrome: https://crbug.com/737228
  3. let hasBoundingRectBug;
  4. function getRectFromEntry(entry) {
  5. if (typeof hasBoundingRectBug !== 'boolean') {
  6. const boundingRect = entry.target.getBoundingClientRect();
  7. const observerRect = entry.boundingClientRect;
  8. hasBoundingRectBug = boundingRect.height !== observerRect.height ||
  9. boundingRect.top !== observerRect.top ||
  10. boundingRect.width !== observerRect.width ||
  11. boundingRect.bottom !== observerRect.bottom ||
  12. boundingRect.left !== observerRect.left ||
  13. boundingRect.right !== observerRect.right;
  14. }
  15. return hasBoundingRectBug ? entry.target.getBoundingClientRect() : entry.boundingClientRect;
  16. }
  17. export default getRectFromEntry;