From fc70921eeb97be7521e9e849016e9f0c4d214538 Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Wed, 5 Oct 2022 07:43:01 +0000 Subject: [PATCH] scroll_util: Add support for sticky headers. When calculating position of an element, we now take into account the height of the sticky headers too. --- static/js/scroll_util.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/static/js/scroll_util.js b/static/js/scroll_util.js index f81ae30a22..7275068121 100644 --- a/static/js/scroll_util.js +++ b/static/js/scroll_util.js @@ -20,20 +20,21 @@ export function scroll_delta(opts) { return delta; } -export function scroll_element_into_container($elem, $container) { +export function scroll_element_into_container($elem, $container, sticky_header_height = 0) { // This does the minimum amount of scrolling that is needed to make // the element visible. It doesn't try to center the element, so // this will be non-intrusive to users when they already have // the element visible. $container = ui.get_scroll_element($container); - const elem_top = $elem.position().top; + const elem_top = $elem.position().top - sticky_header_height; const elem_bottom = elem_top + $elem.innerHeight(); + const container_height = $container.height() - sticky_header_height; const opts = { elem_top, elem_bottom, - container_height: $container.height(), + container_height, }; const delta = scroll_delta(opts);