Skip to content

Commit 65253ed

Browse files
committed
Undo changes to scrolling in common.ts, and instead just add position: relative to .study-list. This fixes a bug where the study list was not being treated as the offsetParent of chapters.
1 parent f08d656 commit 65253ed

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

ui/analyse/css/study/_list.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
min-height: 16em;
6969
max-height: 16em;
7070
}
71+
position: relative;
7172
display: flex;
7273
flex-direction: column;
7374
overflow: hidden;

ui/lib/src/common.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,10 @@ export const scrollToInnerSelector = (el: HTMLElement, selector: string, horiz:
7777
scrollTo(el, el.querySelector(selector), horiz);
7878

7979
export const scrollTo = (el: HTMLElement, target: HTMLElement | null, horiz: boolean = false): void => {
80-
if (!target) return;
81-
if (horiz) {
82-
const delta = target.getBoundingClientRect().left - el.getBoundingClientRect().left;
83-
const desired = el.scrollLeft + delta - (el.clientWidth - target.clientWidth) / 2;
84-
el.scrollLeft = Math.max(0, Math.min(desired, el.scrollWidth - el.clientWidth));
85-
} else {
86-
const delta = target.getBoundingClientRect().top - el.getBoundingClientRect().top;
87-
const desired = el.scrollTop + delta - (el.clientHeight - target.clientHeight) / 2;
88-
el.scrollTop = Math.max(0, Math.min(desired, el.scrollHeight - el.clientHeight));
89-
}
80+
if (target)
81+
horiz
82+
? (el.scrollLeft = target.offsetLeft - el.offsetWidth / 2 + target.offsetWidth / 2)
83+
: (el.scrollTop = target.offsetTop - el.offsetHeight / 2 + target.offsetHeight / 2);
9084
};
9185

9286
export const onClickAway =

0 commit comments

Comments
 (0)