While reading a long page, I often scroll halfway down and then click a .more-info link to expand the side info panel. The panel expansion is useful, but it also moves the content I was reading out of view, which forces me to find my place again every single time. This is disruptive during reviewing/reading and makes the .more-info affordance something I avoid using rather than something I use freely.
Current Behavior
Scroll to roughly the middle of the page.
Click a element of .more-info.
The side info panel expands as expected.
However, the visible portion of the page changes – the scroll position is no longer anchored to the content that was being displayed before the click. The element that was at (or near) the top of the viewport is displaced, so the reader loses their place.
Observed on OneDev 17.2.4.
Expected Behavior
Expanding (or collapsing) the side info panel should not change what the reader is looking at. Whatever content is currently in the viewport before the click should remain in the same position in the viewport afterwards – i.e. the scroll location should stay anchored to the currently displayed content. Only the panel area should reflow.
Proposed Solution
Anchor the scroll position across the layout change caused by the panel expansion:
Try CSS scroll anchoring first. Ensure overflow-anchor is not disabled (overflow-anchor: none) on the containers involved in the reflow, and that the main content area (the scroll container) has overflow-anchor: auto. If the panel and the content live in different scroll containers, or the changed subtree is excluded from anchoring, the browser can't compensate and the viewport jumps — so verify this before writing JS.
If CSS anchoring isn't sufficient, compensate manually in JS. In the click handler for the .more-info link:
Before expanding, record the first visible content element and its offset relative to the viewport top (e.g. via getBoundingClientRect()), together with the current scrollTop.
Expand the panel.
In the same frame/after layout (e.g. requestAnimationFrame), compute the element's new offset and adjust scrollTop by the delta so the element returns to the same viewport position.
Apply the same logic on collapse, and guard against no-op cases (delta 0, element no longer in DOM).
Avoid the root cause if possible. If the jump is caused by the panel being inserted above/inside the content flow rather than overlaying it, consider making the panel an overlay/fixed-position element that does not affect document height at all — that removes the need for any scroll compensation.
Investigation Notes (if the above doesn't resolve it)
Reproduce on a page that requires vertical scrolling (long issue/PR description) and check whether the browser's scroll anchoring is active on the scroll container (devtools: toggle overflow-anchor and compare behavior).
Determine whether the .more-info panel changes document height or whether the content is re-laid out (e.g. width reduction causing text reflow), since width-induced reflow changes the height of content and is a separate class of jump than a pure height change.
Check whether the click handler itself causes a scroll (e.g. focus() on the link, scrollIntoView() somewhere in the expand logic, or an anchor href="#" being followed).
Motivation
While reading a long page, I often scroll halfway down and then click a
.more-infolink to expand the side info panel. The panel expansion is useful, but it also moves the content I was reading out of view, which forces me to find my place again every single time. This is disruptive during reviewing/reading and makes the.more-infoaffordance something I avoid using rather than something I use freely.Current Behavior
aelement of.more-info.Observed on OneDev 17.2.4.
Expected Behavior
Expanding (or collapsing) the side info panel should not change what the reader is looking at. Whatever content is currently in the viewport before the click should remain in the same position in the viewport afterwards – i.e. the scroll location should stay anchored to the currently displayed content. Only the panel area should reflow.
Proposed Solution
Anchor the scroll position across the layout change caused by the panel expansion:
overflow-anchoris not disabled (overflow-anchor: none) on the containers involved in the reflow, and that the main content area (the scroll container) hasoverflow-anchor: auto. If the panel and the content live in different scroll containers, or the changed subtree is excluded from anchoring, the browser can't compensate and the viewport jumps — so verify this before writing JS..more-infolink:getBoundingClientRect()), together with the currentscrollTop.requestAnimationFrame), compute the element's new offset and adjustscrollTopby the delta so the element returns to the same viewport position.Investigation Notes (if the above doesn't resolve it)
overflow-anchorand compare behavior)..more-infopanel changes document height or whether the content is re-laid out (e.g. width reduction causing text reflow), since width-induced reflow changes the height of content and is a separate class of jump than a pure height change.focus()on the link,scrollIntoView()somewhere in the expand logic, or an anchorhref="#"being followed).