Browse Source

🔍 Implemented isInViewport function

📐 Checks if an element is in the viewport
👀 Helps with visibility detection
🪄 Added utility for handling visibility
 Code looks good and is ready for use
main
John Doe 1 year ago
parent
commit
9e2142a38a
  1. 10
      src/utils/isInViewport.ts

10
src/utils/isInViewport.ts

@ -0,0 +1,10 @@
export default function isInViewport(element: HTMLElement) {
const rect = element.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <=
(window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
);
}
Loading…
Cancel
Save