This commit is contained in:
parent
68d647d6b8
commit
8213380ded
|
@ -226,6 +226,10 @@ watch([$$(weakBacked), $$(contentEl)], () => {
|
||||||
})();
|
})();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function preventDefault(ev: Event) {
|
||||||
|
ev.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* アイテムを上に追加した場合に追加分だけスクロールを下にずらす
|
* アイテムを上に追加した場合に追加分だけスクロールを下にずらす
|
||||||
* @param fn DOM操作(unshiftItemsなどで)
|
* @param fn DOM操作(unshiftItemsなどで)
|
||||||
|
@ -234,12 +238,16 @@ function adjustScroll(fn: () => void): Promise<void> {
|
||||||
const oldHeight = scrollableElement ? scrollableElement.scrollHeight : getBodyScrollHeight();
|
const oldHeight = scrollableElement ? scrollableElement.scrollHeight : getBodyScrollHeight();
|
||||||
const oldScroll = scrollableElement ? scrollableElement.scrollTop : window.scrollY;
|
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' });
|
scroll(scrollableElement, { top: oldScroll, behavior: 'instant' });
|
||||||
|
|
||||||
fn();
|
fn();
|
||||||
return nextTick(() => {
|
return nextTick(() => {
|
||||||
const top = oldScroll + ((scrollableElement ? scrollableElement.scrollHeight : getBodyScrollHeight()) - oldHeight);
|
const top = oldScroll + ((scrollableElement ? scrollableElement.scrollHeight : getBodyScrollHeight()) - oldHeight);
|
||||||
scroll(scrollableElement, { top, behavior: 'instant' });
|
scroll(scrollableElement, { top, behavior: 'instant' });
|
||||||
|
scrollableElementOrHtml.removeEventListener('mousewheel', preventDefault);
|
||||||
|
scrollableElementOrHtml.removeEventListener('touchmove', preventDefault);
|
||||||
return nextTick();
|
return nextTick();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue