]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/helpers/utils/ui.ts
Continue user mute in ban modal PR
[github/Chocobozzz/PeerTube.git] / client / src / app / helpers / utils / ui.ts
CommitLineData
dd24f1bb
C
1function scrollToTop (behavior: 'auto' | 'smooth' = 'auto') {
2 window.scrollTo({
3 left: 0,
4 top: 0,
5 behavior
6 })
7}
8
9function 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
19function 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
29export {
30 scrollToTop,
31 isInViewport,
32 isXPercentInViewport
33}