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)