1 function scrollToTop (behavior: 'auto' | 'smooth' = 'auto') {
9 function isInViewport (el: HTMLElement, container: HTMLElement = document.documentElement) {
10 const boundingEl = el.getBoundingClientRect()
11 const boundingContainer = container.getBoundingClientRect()
20 relativePos.top = boundingEl.top - boundingContainer.top
21 relativePos.left = boundingEl.left - boundingContainer.left
23 return relativePos.top >= 0 &&
24 relativePos.left >= 0 &&
25 boundingEl.bottom <= boundingContainer.bottom &&
26 boundingEl.right <= boundingContainer.right
29 function isXPercentInViewport (el: HTMLElement, percentVisible: number) {
30 const rect = el.getBoundingClientRect()
31 const windowHeight = (window.innerHeight || document.documentElement.clientHeight)
34 Math.floor(100 - (((rect.top >= 0 ? 0 : rect.top) / +-(rect.height / 1)) * 100)) < percentVisible ||
35 Math.floor(100 - ((rect.bottom - windowHeight) / rect.height) * 100) < percentVisible