This repository has been archived on 2024-02-08. You can view files and clone it, but cannot push or open issues or pull requests.
frontend/src/helpers/scrollIntoView.ts
Dominik Pschenitschni 2dc36c032b
Some checks failed
continuous-integration/drone/push Build is failing
feat: TaskDetail as script setup (#1792)
Co-authored-by: Dominik Pschenitschni <mail@celement.de>
Reviewed-on: #1792
Reviewed-by: konrad <k@knt.li>
Co-authored-by: Dominik Pschenitschni <dpschen@noreply.kolaente.de>
Co-committed-by: Dominik Pschenitschni <dpschen@noreply.kolaente.de>
2022-10-01 15:02:35 +00:00

19 lines
367 B
TypeScript

export function scrollIntoView(el: HTMLElement | null | undefined) {
if (!el) {
return
}
const boundingRect = el.getBoundingClientRect()
const scrollY = window.scrollY
if (
boundingRect.top > (scrollY + window.innerHeight) ||
boundingRect.top < scrollY
) {
el.scrollIntoView({
behavior: 'smooth',
block: 'center',
inline: 'nearest',
})
}
}