nextTick?

This commit is contained in:
tamaina 2023-07-18 03:33:38 +00:00
parent cb63a1ed00
commit 0079f3394b
1 changed files with 6 additions and 4 deletions

View File

@ -251,7 +251,11 @@ function preventDefault(ev: Event) {
* ChromeやFirefoxはこれをいい感じにやってくれるがSafariはやってくれないため自分で実装する必要がある * ChromeやFirefoxはこれをいい感じにやってくれるがSafariはやってくれないため自分で実装する必要がある
* @param fn DOM操作(unshiftItemsなどで) * @param fn DOM操作(unshiftItemsなどで)
*/ */
function adjustScroll(fn: () => void): Promise<void> { async function adjustScroll(fn: () => void): Promise<void> {
denyMoveTransition.value = true;
await nextTick();
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;
// //
@ -265,11 +269,9 @@ function adjustScroll(fn: () => void): Promise<void> {
console.error(err, { scrollableElementOrHtml }); console.error(err, { scrollableElementOrHtml });
} }
denyMoveTransition.value = true;
fn(); fn();
return nextTick(() => { return await nextTick(() => {
try { try {
// scrollBy // scrollBy
const top = oldScroll + ((scrollableElement ? scrollableElement.scrollHeight : getBodyScrollHeight()) - oldHeight); const top = oldScroll + ((scrollableElement ? scrollableElement.scrollHeight : getBodyScrollHeight()) - oldHeight);