aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/helpers/utils/ui.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-08-19 09:24:29 +0200
committerChocobozzz <me@florianbigard.com>2021-08-25 11:24:11 +0200
commitdd24f1bb0a4b252e5342b251ba36853364da7b8e (patch)
tree41a9506d07413f056fb90425705e258f96fdc77d /client/src/app/helpers/utils/ui.ts
parent2e80d256cc75b4b02c8efc3d3e4cdf57ddf401a8 (diff)
downloadPeerTube-dd24f1bb0a4b252e5342b251ba36853364da7b8e.tar.gz
PeerTube-dd24f1bb0a4b252e5342b251ba36853364da7b8e.tar.zst
PeerTube-dd24f1bb0a4b252e5342b251ba36853364da7b8e.zip
Add video filters to common video pages
Diffstat (limited to 'client/src/app/helpers/utils/ui.ts')
-rw-r--r--client/src/app/helpers/utils/ui.ts33
1 files changed, 33 insertions, 0 deletions
diff --git a/client/src/app/helpers/utils/ui.ts b/client/src/app/helpers/utils/ui.ts
new file mode 100644
index 000000000..ac8298926
--- /dev/null
+++ b/client/src/app/helpers/utils/ui.ts
@@ -0,0 +1,33 @@
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}