Skip to content

Commit af8ebc2

Browse files
authored
Detect if Browser Tab is in the view
1 parent 32cabe1 commit af8ebc2

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

README.md

+18
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
|26 | [getBoundingClientRect](#getBoundingClientRect)|
3333
|27 | [Check if a node is in the viewport](#Check-if-a-node-is-in-the-viewport)|
3434
|28 | [Notify when element size is changed](#Notify-when-element-size-is-changed)|
35+
|29 | [Detect if Browser Tab is in the view](#Detect-if-Browser-Tab-is-in-the-view)|
3536

3637

3738

@@ -592,6 +593,23 @@ const observer = new ResizeObserver((entries) => {
592593
});
593594
observer.observe(foo);
594595

596+
```
597+
**[⬆ Back to Top](#table-of-contents)**
598+
### Detect if Browser Tab is in the view
599+
play/pause video accordingly
600+
see our codepen: https://codepen.io/JSsnippets/pen/gOapPzq
601+
```javascript
602+
603+
604+
const video = document.getElementById("my-video");
605+
606+
const onVisibilitychange =()=>{
607+
return document.hidden
608+
? video.pause()
609+
: video.play();
610+
}
611+
612+
document.addEventListener("visibilitychange", onVisibilitychange)
595613

596614
```
597615

0 commit comments

Comments
 (0)