X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fshared%2Fmisc%2Futils.ts;h=b1d1fc0b5257a7f3d4c5795e5c8727cab9ab7810;hb=223b24e618146f85b20b5bf365bc18d14a5964cd;hp=f26240d216eee3461aab8d85eb20f12326d386b0;hpb=1dc240a9488c66ad38205d08fcfdb32d35efceaa;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/shared/misc/utils.ts b/client/src/app/shared/misc/utils.ts index f26240d21..b1d1fc0b5 100644 --- a/client/src/app/shared/misc/utils.ts +++ b/client/src/app/shared/misc/utils.ts @@ -169,6 +169,26 @@ function importModule (path: string) { }) } +function isInViewport (el: HTMLElement) { + const bounding = el.getBoundingClientRect() + return ( + bounding.top >= 0 && + bounding.left >= 0 && + bounding.bottom <= (window.innerHeight || document.documentElement.clientHeight) && + bounding.right <= (window.innerWidth || document.documentElement.clientWidth) + ) +} + +function isXPercentInViewport (el: HTMLElement, percentVisible: number) { + const rect = el.getBoundingClientRect() + const windowHeight = (window.innerHeight || document.documentElement.clientHeight) + + return !( + Math.floor(100 - (((rect.top >= 0 ? 0 : rect.top) / +-(rect.height / 1)) * 100)) < percentVisible || + Math.floor(100 - ((rect.bottom - windowHeight) / rect.height) * 100) < percentVisible + ) +} + export { sortBy, durationToString, @@ -183,5 +203,7 @@ export { objectLineFeedToHtml, removeElementFromArray, importModule, - scrollToTop + scrollToTop, + isInViewport, + isXPercentInViewport }