Files
Desktop/ts/util/scrollUtil.std.ts
2026-03-30 12:27:16 -07:00

24 lines
789 B
TypeScript

// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
export const getScrollBottom = (
el: Readonly<Pick<HTMLElement, 'clientHeight' | 'scrollHeight' | 'scrollTop'>>
): number => el.scrollHeight - el.scrollTop - el.clientHeight;
export function setScrollBottom(
el: Pick<HTMLElement, 'clientHeight' | 'scrollHeight' | 'scrollTop'>,
newScrollBottom: number
): void {
// We want to mutate the parameter here.
// oxlint-disable-next-line no-param-reassign
el.scrollTop = el.scrollHeight - newScrollBottom - el.clientHeight;
}
export function scrollToBottom(
el: Pick<HTMLElement, 'scrollHeight' | 'scrollTop'>
): void {
// We want to mutate the parameter here.
// oxlint-disable-next-line no-param-reassign
el.scrollTop = el.scrollHeight;
}