mirror of
https://github.com/vrtmrz/ninja-cursor.git
synced 2026-07-22 06:40:31 +00:00
Improved: Improved scrolling performance.
This commit is contained in:
parent
75692110ec
commit
c8419d3afd
1 changed files with 16 additions and 12 deletions
28
main.ts
28
main.ts
|
|
@ -142,20 +142,25 @@ class NinjaCursorForWindow {
|
|||
moveCursor(ev);
|
||||
});
|
||||
}
|
||||
let triggered = false;
|
||||
// Handles scroll till scroll is finish.
|
||||
const applyWheelScroll = (last?: number | boolean) => {
|
||||
requestAnimationFrame(() => {
|
||||
if (datumElement) {
|
||||
const curTop = datumElement.getBoundingClientRect().top;
|
||||
const diff = curTop - datumTop;
|
||||
root.style.setProperty("--cursor-offset-y", `${diff}px`);
|
||||
if (last === false || last != diff) {
|
||||
requestAnimationFrame(() => applyWheelScroll(diff));
|
||||
} else if (last == diff) {
|
||||
moveCursor(undefined, true);
|
||||
if (!triggered) {
|
||||
requestAnimationFrame(() => {
|
||||
if (datumElement) {
|
||||
const curTop = datumElement.getBoundingClientRect().top;
|
||||
const diff = curTop - datumTop;
|
||||
root.style.setProperty("--cursor-offset-y", `${diff}px`);
|
||||
if (last === false || last != diff) {
|
||||
requestAnimationFrame(() => applyWheelScroll(diff));
|
||||
} else if (last == diff) {
|
||||
moveCursor(undefined, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
triggered = false;
|
||||
});
|
||||
triggered = true;
|
||||
}
|
||||
}
|
||||
registerDomEvent(aw, "wheel", (e: WheelEvent) => {
|
||||
applyWheelScroll(false);
|
||||
|
|
@ -180,7 +185,6 @@ export default class NinjaCursorPlugin extends Plugin {
|
|||
|
||||
async onload() {
|
||||
|
||||
|
||||
this.registerEvent(this.app.workspace.on("window-open", (win) => {
|
||||
console.log("Open by window-open")
|
||||
const exist = this.Cursors.find(e => e.bufferedWindow == win.win);
|
||||
|
|
|
|||
Loading…
Reference in a new issue