This commit is contained in:
tamaina 2022-03-05 20:04:48 +09:00
parent 17d71fa0ad
commit 6dc9a6ccc3

View File

@ -102,18 +102,20 @@ const {
const contentEl = $computed(() => props.pagination.pageEl || rootEl);
const scrollableElement = $computed(() => getScrollContainer(contentEl));
const observer = $computed(() => new IntersectionObserver(entries => {
backed = props.pagination.reversed ? !entries[0].isIntersecting : entries[0].isIntersecting;
//
// https://qiita.com/mkataigi/items/0154aefd2223ce23398e
const scrollObserver = $computed(() => new IntersectionObserver(entries => {
backed = entries[0].isIntersecting;
}, {
root: scrollableElement,
rootMargin: props.pagination.reversed ? "-100% 0px 100% 0px" : "100% 0px -100% 0px",
threshold: 0.01,
}));
watch($$(contentEl), () => {
observer.disconnect();
watch($$(rootEl), () => {
scrollObserver.disconnect();
nextTick(() => {
if (contentEl) observer.observe(contentEl);
if (rootEl) scrollObserver.observe(rootEl);
});
});
@ -339,7 +341,7 @@ onMounted(() => {
});
onBeforeUnmount(() => {
observer.disconnect();
scrollObserver.disconnect();
});
defineExpose({