]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/helpers/utils/ui.ts
Add video filters to common video pages
[github/Chocobozzz/PeerTube.git] / client / src / app / helpers / utils / ui.ts
1 function scrollToTop (behavior: 'auto' | 'smooth' = 'auto') {
2 window.scrollTo({
3 left: 0,
4 top: 0,
5 behavior
6 })
7 }
8
9 function isInViewport (el: HTMLElement) {
10 const bounding = el.getBoundingClientRect()
11 return (
12 bounding.top >= 0 &&
13 bounding.left >= 0 &&
14 bounding.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
15 bounding.right <= (window.innerWidth || document.documentElement.clientWidth)
16 )
17 }
18
19 function isXPercentInViewport (el: HTMLElement, percentVisible: number) {
20 const rect = el.getBoundingClientRect()
21 const windowHeight = (window.innerHeight || document.documentElement.clientHeight)
22
23 return !(
24 Math.floor(100 - (((rect.top >= 0 ? 0 : rect.top) / +-(rect.height / 1)) * 100)) < percentVisible ||
25 Math.floor(100 - ((rect.bottom - windowHeight) / rect.height) * 100) < percentVisible
26 )
27 }
28
29 export {
30 scrollToTop,
31 isInViewport,
32 isXPercentInViewport
33 }