This commit is contained in:
tamaina 2022-02-03 04:28:04 +09:00
parent de90b25561
commit a2f16c1364
2 changed files with 9 additions and 8 deletions

View file

@ -32,7 +32,7 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { computed, ComputedRef, isRef, nextTick, onActivated, onBeforeUnmount, onDeactivated, onMounted, ref, watch } from 'vue'; import { computed, ComputedRef, isRef, nextTick, onActivated, onBeforeUnmount, onDeactivated, onMounted, ref, watch, watchEffect } from 'vue';
import * as misskey from 'misskey-js'; import * as misskey from 'misskey-js';
import * as os from '@/os'; import * as os from '@/os';
import { onScrollTop, isTopVisible, getBodyScrollHeight, getScrollContainer, onScrollBottom, scrollToBottom, scroll, isBottomVisible } from '@/scripts/scroll'; import { onScrollTop, isTopVisible, getBodyScrollHeight, getScrollContainer, onScrollBottom, scrollToBottom, scroll, isBottomVisible } from '@/scripts/scroll';
@ -130,7 +130,8 @@ const observer = new IntersectionObserver(entries => {
} }
}); });
watch([items, $$(itemsContainer), $$(rootEl)], observeLatestElement); watch([$$(itemsContainer), $$(rootEl)], observeLatestElement);
watch(items, observeLatestElement, { deep: true });
function observeLatestElement() { function observeLatestElement() {
observer.disconnect(); observer.disconnect();
@ -141,7 +142,7 @@ function observeLatestElement() {
}); });
} }
watch($$(backed), () => { watch([$$(backed), $$(contentEl)], () => {
if (!backed) { if (!backed) {
if (!contentEl) return; if (!contentEl) return;
@ -151,7 +152,7 @@ watch($$(backed), () => {
prepend(item, true); prepend(item, true);
} }
queue.value = []; queue.value = [];
}); }, 16);
} else { } else {
if (scrollRemove) scrollRemove(); if (scrollRemove) scrollRemove();
scrollRemove = null; scrollRemove = null;

View file

@ -25,7 +25,7 @@ export function getScrollPosition(el: HTMLElement | null): number {
return container == null ? window.scrollY : container.scrollTop; return container == null ? window.scrollY : container.scrollTop;
} }
export function onScrollTop(el: HTMLElement, cb: Function) { export function onScrollTop(el: HTMLElement, cb: Function, asobi: number = 1) {
// とりあえず評価してみる // とりあえず評価してみる
if (isTopVisible(el)) { if (isTopVisible(el)) {
cb(); cb();
@ -36,7 +36,7 @@ export function onScrollTop(el: HTMLElement, cb: Function) {
const onScroll = ev => { const onScroll = ev => {
if (!document.body.contains(el)) return; if (!document.body.contains(el)) return;
if (isTopVisible(el)) { if (isTopVisible(el, asobi)) {
cb(); cb();
removeListener(); removeListener();
} }
@ -47,11 +47,11 @@ export function onScrollTop(el: HTMLElement, cb: Function) {
return removeListener; return removeListener;
} }
export function onScrollBottom(el: HTMLElement, cb: Function) { export function onScrollBottom(el: HTMLElement, cb: Function, asobi: number = 1) {
const container = getScrollContainer(el); const container = getScrollContainer(el);
// とりあえず評価してみる // とりあえず評価してみる
if (isBottomVisible(el, 1, container)) { if (isBottomVisible(el, asobi, container)) {
cb(); cb();
return null; return null;
} }