diff options
Diffstat (limited to 'client/src/app/shared/misc')
-rw-r--r-- | client/src/app/shared/misc/utils.ts | 24 |
1 files changed, 23 insertions, 1 deletions
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) { | |||
169 | }) | 169 | }) |
170 | } | 170 | } |
171 | 171 | ||
172 | function isInViewport (el: HTMLElement) { | ||
173 | const bounding = el.getBoundingClientRect() | ||
174 | return ( | ||
175 | bounding.top >= 0 && | ||
176 | bounding.left >= 0 && | ||
177 | bounding.bottom <= (window.innerHeight || document.documentElement.clientHeight) && | ||
178 | bounding.right <= (window.innerWidth || document.documentElement.clientWidth) | ||
179 | ) | ||
180 | } | ||
181 | |||
182 | function isXPercentInViewport (el: HTMLElement, percentVisible: number) { | ||
183 | const rect = el.getBoundingClientRect() | ||
184 | const windowHeight = (window.innerHeight || document.documentElement.clientHeight) | ||
185 | |||
186 | return !( | ||
187 | Math.floor(100 - (((rect.top >= 0 ? 0 : rect.top) / +-(rect.height / 1)) * 100)) < percentVisible || | ||
188 | Math.floor(100 - ((rect.bottom - windowHeight) / rect.height) * 100) < percentVisible | ||
189 | ) | ||
190 | } | ||
191 | |||
172 | export { | 192 | export { |
173 | sortBy, | 193 | sortBy, |
174 | durationToString, | 194 | durationToString, |
@@ -183,5 +203,7 @@ export { | |||
183 | objectLineFeedToHtml, | 203 | objectLineFeedToHtml, |
184 | removeElementFromArray, | 204 | removeElementFromArray, |
185 | importModule, | 205 | importModule, |
186 | scrollToTop | 206 | scrollToTop, |
207 | isInViewport, | ||
208 | isXPercentInViewport | ||
187 | } | 209 | } |