Merge branch 'develop' into vue3
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { getScrollPosition, onScrollTop } from './scroll';
|
||||
import { onScrollTop, isTopVisible } from './scroll';
|
||||
|
||||
const SECOND_FETCH_LIMIT = 30;
|
||||
|
||||
@@ -147,7 +147,7 @@ export default (opts) => ({
|
||||
},
|
||||
|
||||
prepend(item) {
|
||||
const isTop = this.isBackTop || (document.body.contains(this.$el) && (getScrollPosition(this.$el) === 0));
|
||||
const isTop = this.isBackTop || (document.body.contains(this.$el) && isTopVisible(this.$el));
|
||||
|
||||
if (isTop) {
|
||||
// Prepend the item
|
||||
|
@@ -13,14 +13,20 @@ export function getScrollPosition(el: Element | null): number {
|
||||
return container == null ? window.scrollY : container.scrollTop;
|
||||
}
|
||||
|
||||
export function isTopVisible(el: Element | null): boolean {
|
||||
const scrollTop = getScrollPosition(el);
|
||||
const topPosition = el.offsetTop; // TODO: container内でのelの相対位置を取得できればより正確になる
|
||||
|
||||
return scrollTop <= topPosition;
|
||||
}
|
||||
|
||||
export function onScrollTop(el: Element, cb) {
|
||||
const container = getScrollContainer(el) || window;
|
||||
const onScroll = ev => {
|
||||
if (!document.body.contains(el)) return;
|
||||
const pos = getScrollPosition(el);
|
||||
if (pos === 0) {
|
||||
if (isTopVisible(el)) {
|
||||
cb();
|
||||
container.removeEventListener('scroll', onscroll);
|
||||
container.removeEventListener('scroll', onScroll);
|
||||
}
|
||||
};
|
||||
container.addEventListener('scroll', onScroll, { passive: true });
|
||||
@@ -33,7 +39,7 @@ export function onScrollBottom(el: Element, cb) {
|
||||
const pos = getScrollPosition(el);
|
||||
if (pos + el.clientHeight > el.scrollHeight - 1) {
|
||||
cb();
|
||||
container.removeEventListener('scroll', onscroll);
|
||||
container.removeEventListener('scroll', onScroll);
|
||||
}
|
||||
};
|
||||
container.addEventListener('scroll', onScroll, { passive: true });
|
||||
|
Reference in New Issue
Block a user