mirror of
https://activitypub.software/TransFem-org/Sharkey
synced 2024-11-24 23:15:13 +00:00
✌️
This commit is contained in:
parent
68d647d6b8
commit
8213380ded
1 changed files with 8 additions and 0 deletions
|
@ -226,6 +226,10 @@ watch([$$(weakBacked), $$(contentEl)], () => {
|
|||
})();
|
||||
});
|
||||
|
||||
function preventDefault(ev: Event) {
|
||||
ev.preventDefault();
|
||||
}
|
||||
|
||||
/**
|
||||
* アイテムを上に追加した場合に追加分だけスクロールを下にずらす
|
||||
* @param fn DOM操作(unshiftItemsなどで)
|
||||
|
@ -234,12 +238,16 @@ function adjustScroll(fn: () => void): Promise<void> {
|
|||
const oldHeight = scrollableElement ? scrollableElement.scrollHeight : getBodyScrollHeight();
|
||||
const oldScroll = scrollableElement ? scrollableElement.scrollTop : window.scrollY;
|
||||
// スクロールをやめさせる
|
||||
scrollableElementOrHtml.addEventListener('mousewheel', preventDefault, { passive: false });
|
||||
scrollableElementOrHtml.addEventListener('touchmove', preventDefault, { passive: false });
|
||||
scroll(scrollableElement, { top: oldScroll, behavior: 'instant' });
|
||||
|
||||
fn();
|
||||
return nextTick(() => {
|
||||
const top = oldScroll + ((scrollableElement ? scrollableElement.scrollHeight : getBodyScrollHeight()) - oldHeight);
|
||||
scroll(scrollableElement, { top, behavior: 'instant' });
|
||||
scrollableElementOrHtml.removeEventListener('mousewheel', preventDefault);
|
||||
scrollableElementOrHtml.removeEventListener('touchmove', preventDefault);
|
||||
return nextTick();
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue