asobi → tolerance

This commit is contained in:
tamaina 2022-05-08 20:56:50 +09:00
parent a0bf73b01b
commit 58509ee84a
2 changed files with 12 additions and 12 deletions

View File

@ -41,7 +41,7 @@ import { defaultStore } from '@/store';
import { MisskeyEntity } from '@/types/date-separated-list';
const SECOND_FETCH_LIMIT = 30;
const ASOBI = 16;
const TOLERANCE = 16;
export type Paging<E extends keyof misskey.Endpoints = keyof misskey.Endpoints> = {
endpoint: E;
@ -121,7 +121,7 @@ watch([$$(backed), $$(contentEl)], () => {
if (!backed) {
if (!contentEl) return;
scrollRemove = (props.pagination.reversed ? onScrollBottom : onScrollTop)(contentEl, executeQueue, ASOBI);
scrollRemove = (props.pagination.reversed ? onScrollBottom : onScrollTop)(contentEl, executeQueue, TOLERANCE);
} else {
if (scrollRemove) scrollRemove();
scrollRemove = null;
@ -273,7 +273,7 @@ const prepend = (item: MisskeyEntity): void => {
return;
}
const isTop = isBackTop.value || (props.pagination.reversed ? isBottomVisible : isTopVisible)(contentEl, ASOBI);
const isTop = isBackTop.value || (props.pagination.reversed ? isBottomVisible : isTopVisible)(contentEl, TOLERANCE);
if (isTop) unshiftItems([item]);
else prependQueue(item);

View File

@ -25,7 +25,7 @@ export function getScrollPosition(el: HTMLElement | null): number {
return container == null ? window.scrollY : container.scrollTop;
}
export function onScrollTop(el: HTMLElement, cb: Function, asobi: number = 1, once: boolean = false) {
export function onScrollTop(el: HTMLElement, cb: Function, tolerance: number = 1, once: boolean = false) {
// とりあえず評価してみる
if (isTopVisible(el)) {
cb();
@ -36,7 +36,7 @@ export function onScrollTop(el: HTMLElement, cb: Function, asobi: number = 1, on
const onScroll = ev => {
if (!document.body.contains(el)) return;
if (isTopVisible(el, asobi)) {
if (isTopVisible(el, tolerance)) {
cb();
if (once) removeListener();
}
@ -47,11 +47,11 @@ export function onScrollTop(el: HTMLElement, cb: Function, asobi: number = 1, on
return removeListener;
}
export function onScrollBottom(el: HTMLElement, cb: Function, asobi: number = 1, once: boolean = false) {
export function onScrollBottom(el: HTMLElement, cb: Function, tolerance: number = 1, once: boolean = false) {
const container = getScrollContainer(el);
// とりあえず評価してみる
if (isBottomVisible(el, asobi, container)) {
if (isBottomVisible(el, tolerance, container)) {
cb();
if (once) return null;
}
@ -109,14 +109,14 @@ export function scrollToBottom(
}
}
export function isTopVisible(el: HTMLElement, asobi: number = 1): boolean {
export function isTopVisible(el: HTMLElement, tolerance: number = 1): boolean {
const scrollTop = getScrollPosition(el);
return scrollTop <= asobi;
return scrollTop <= tolerance;
}
export function isBottomVisible(el: HTMLElement, asobi = 1, container = getScrollContainer(el)) {
if (container) return el.scrollHeight <= container.clientHeight + Math.abs(container.scrollTop) + asobi;
return el.scrollHeight <= window.innerHeight + window.scrollY + asobi;
export function isBottomVisible(el: HTMLElement, tolerance = 1, container = getScrollContainer(el)) {
if (container) return el.scrollHeight <= container.clientHeight + Math.abs(container.scrollTop) + tolerance;
return el.scrollHeight <= window.innerHeight + window.scrollY + tolerance;
}
// https://ja.javascript.info/size-and-scroll-window#ref-932