Merge branch 'develop' into swn
This commit is contained in:
@@ -4,7 +4,6 @@ import {
|
||||
get as iget,
|
||||
set as iset,
|
||||
del as idel,
|
||||
createStore,
|
||||
} from 'idb-keyval';
|
||||
|
||||
const fallbackName = (key: string) => `idbfallback::${key}`;
|
||||
@@ -13,9 +12,9 @@ let idbAvailable = typeof window !== 'undefined' ? !!window.indexedDB : true;
|
||||
|
||||
if (idbAvailable) {
|
||||
try {
|
||||
await createStore('keyval-store', 'keyval');
|
||||
await iset('idb-test', 'test');
|
||||
} catch (e) {
|
||||
console.error('idb open error', e);
|
||||
console.error('idb error', e);
|
||||
idbAvailable = false;
|
||||
}
|
||||
}
|
||||
|
@@ -1,3 +1,5 @@
|
||||
type ScrollBehavior = 'auto' | 'smooth' | 'instant';
|
||||
|
||||
export function getScrollContainer(el: Element | null): Element | null {
|
||||
if (el == null || el.tagName === 'BODY') return null;
|
||||
const overflow = window.getComputedStyle(el).getPropertyValue('overflow');
|
||||
@@ -45,21 +47,25 @@ export function onScrollBottom(el: Element, cb) {
|
||||
container.addEventListener('scroll', onScroll, { passive: true });
|
||||
}
|
||||
|
||||
export function scroll(el: Element, top: number) {
|
||||
export function scroll(el: Element, options: {
|
||||
top?: number;
|
||||
left?: number;
|
||||
behavior?: ScrollBehavior;
|
||||
}) {
|
||||
const container = getScrollContainer(el);
|
||||
if (container == null) {
|
||||
window.scroll({ top: top, behavior: 'instant' });
|
||||
window.scroll(options);
|
||||
} else {
|
||||
container.scrollTop = top;
|
||||
container.scroll(options);
|
||||
}
|
||||
}
|
||||
|
||||
export function scrollToTop(el: Element) {
|
||||
scroll(el, 0);
|
||||
export function scrollToTop(el: Element, options: { behavior?: ScrollBehavior; } = {}) {
|
||||
scroll(el, { top: 0, ...options });
|
||||
}
|
||||
|
||||
export function scrollToBottom(el: Element) {
|
||||
scroll(el, 99999); // TODO: ちゃんと計算する
|
||||
export function scrollToBottom(el: Element, options: { behavior?: ScrollBehavior; } = {}) {
|
||||
scroll(el, { top: 99999, ...options }); // TODO: ちゃんと計算する
|
||||
}
|
||||
|
||||
export function isBottom(el: Element, asobi = 0) {
|
||||
|
Reference in New Issue
Block a user