mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-26 03:47:40 -07:00
refactor: use overflow-y to determine scroll container
By using `overflow-y` instead of `overflow` using `endsWith` can be avoided and represents the data we are actually interested in here more accurately.
This commit is contained in:
parent
0af344b4e3
commit
1c0966726b
1 changed files with 2 additions and 6 deletions
|
@ -2,12 +2,8 @@ type ScrollBehavior = 'auto' | 'smooth' | 'instant';
|
||||||
|
|
||||||
export function getScrollContainer(el: HTMLElement | null): HTMLElement | null {
|
export function getScrollContainer(el: HTMLElement | null): HTMLElement | null {
|
||||||
if (el == null || el.tagName === 'HTML') return null;
|
if (el == null || el.tagName === 'HTML') return null;
|
||||||
const overflow = window.getComputedStyle(el).getPropertyValue('overflow');
|
const overflow = window.getComputedStyle(el).getPropertyValue('overflow-y');
|
||||||
if (
|
if (overflow === 'scroll' || overflow === 'auto') {
|
||||||
// xとyを個別に指定している場合、`hidden scroll`みたいな値になる
|
|
||||||
overflow.endsWith('scroll') ||
|
|
||||||
overflow.endsWith('auto')
|
|
||||||
) {
|
|
||||||
return el;
|
return el;
|
||||||
} else {
|
} else {
|
||||||
return getScrollContainer(el.parentElement);
|
return getScrollContainer(el.parentElement);
|
||||||
|
|
Loading…
Reference in a new issue