- Improve scroll behavior between active sections - Improve lag when clicking on a sidebar item - Refactor internal working of the `SidebarProvider` to find active items faster. - Use Next.js's `useRouter` hook for changing the hash (since they added the option to disable scroll) - Change `isBrowser` from a hook to a provider since it's widely used across applications. - Other general improvements and fixes. Closes DOCS-952
16 lines
455 B
TypeScript
16 lines
455 B
TypeScript
export default function checkElementInViewport(
|
|
element: Element,
|
|
percentage = 100
|
|
) {
|
|
const rect = element.getBoundingClientRect()
|
|
const windowHeight: number | undefined =
|
|
window.innerHeight || document.documentElement.clientHeight
|
|
|
|
return !(
|
|
Math.floor(100 - ((rect.top >= 0 ? 0 : rect.top) / +-rect.height) * 100) <
|
|
percentage ||
|
|
Math.floor(100 - ((rect.bottom - windowHeight) / rect.height) * 100) <
|
|
percentage
|
|
)
|
|
}
|