Skip to content

Commit 603fba5

Browse files
authored
check if a node is in the viewport
1 parent a23d648 commit 603fba5

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,23 @@ const bodyBounderies = document.body.getBoundingClientRect();
525525
```
526526
527527
528+
# Check if a node is in the viewport
528529
530+
```javascript
531+
const image = document.querySelector('.animate-me');
532+
533+
observer = new IntersectionObserver((entries) => {
534+
const [ myImg ] = entries;
535+
if (myImg.intersectionRatio > 0) {
536+
myImg.target.classList.add('fancy');
537+
} else {
538+
myImg.target.classList.remove('fancy');
539+
}
540+
});
541+
542+
543+
observer.observe(image);
544+
545+
```
529546
530547

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy