mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-18 10:36:22 +08:00
refactor(editor): extract drag handle widget (#9415)
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
export function autoScroll(
|
||||
viewportElement: HTMLElement,
|
||||
y: number,
|
||||
threshold = 50
|
||||
): boolean {
|
||||
const { scrollHeight, clientHeight, scrollTop } = viewportElement;
|
||||
let _scrollTop = scrollTop;
|
||||
const max = scrollHeight - clientHeight;
|
||||
|
||||
let d = 0;
|
||||
let flag = false;
|
||||
|
||||
if (Math.ceil(scrollTop) < max && clientHeight - y < threshold) {
|
||||
// ↓
|
||||
d = threshold - (clientHeight - y);
|
||||
flag = Math.ceil(_scrollTop) < max;
|
||||
} else if (scrollTop > 0 && y < threshold) {
|
||||
// ↑
|
||||
d = y - threshold;
|
||||
flag = _scrollTop > 0;
|
||||
}
|
||||
|
||||
_scrollTop += d * 0.25;
|
||||
|
||||
if (flag && scrollTop !== _scrollTop) {
|
||||
viewportElement.scrollTop = _scrollTop;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user