enhance(frontend): チャット画面で確実に最下部へスクロール追従するように
This commit is contained in:
parent
600bb34172
commit
8cbcbd462c
2 changed files with 44 additions and 2 deletions
21
packages/frontend/src/use/use-mutation-observer.ts
Normal file
21
packages/frontend/src/use/use-mutation-observer.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: syuilo and misskey-project
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { onUnmounted, watch } from 'vue';
|
||||
import type { Ref, ShallowRef } from 'vue';
|
||||
|
||||
export function useMutationObserver(targetNodeRef: Ref<HTMLElement | undefined>, options: MutationObserverInit, callback: MutationCallback): void {
|
||||
const observer = new MutationObserver(callback);
|
||||
|
||||
watch(targetNodeRef, (targetNode) => {
|
||||
if (targetNode) {
|
||||
observer.observe(targetNode, options);
|
||||
}
|
||||
}, { immediate: true });
|
||||
|
||||
onUnmounted(() => {
|
||||
observer.disconnect();
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue