Skip to content

Commit

Permalink
Feat: Add scroll event listener to ScrollBox
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberDex committed Jul 30, 2024
1 parent 2faea73 commit 9b51c72
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/ScrollBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export class ScrollBox extends Container
protected lastScrollY!: number | null;
protected proximityCheckFrameCounter = 0;
public onProximityChange = new Signal<(data: ProximityEventData) => void>();
public onScroll: Signal<(value: number) => void> = new Signal();

/**
* @param options
Expand Down Expand Up @@ -567,6 +568,9 @@ export class ScrollBox extends Container

protected onMouseScroll(event: WheelEvent): void
{
const isVertical: boolean = this.options.type !== 'horizontal';
const oldScrollPos = isVertical ? this.scrollY : this.scrollX;

if (!this.isOver && !this.options.globalScroll) return;

this.renderAllItems();
Expand Down Expand Up @@ -610,6 +614,13 @@ export class ScrollBox extends Container
}

this.stopRenderHiddenItems();


Check warning on line 618 in src/ScrollBox.ts

View workflow job for this annotation

GitHub Actions / build

More than 1 blank line not allowed
const newScrollPos = isVertical ? this.scrollY : this.scrollX;

if (newScrollPos !== oldScrollPos) {

Check warning on line 621 in src/ScrollBox.ts

View workflow job for this annotation

GitHub Actions / build

Opening curly brace appears on the same line as controlling statement
this.onScroll?.emit(newScrollPos);
}
}

/** Makes it scroll down to the last element. */
Expand Down Expand Up @@ -872,4 +883,12 @@ export class ScrollBox extends Container
item.children.forEach((child) => this.revertClick(child));
}
}

get scrollHeight(): number {

Check warning on line 887 in src/ScrollBox.ts

View workflow job for this annotation

GitHub Actions / build

Opening curly brace appears on the same line as controlling statement
return this.list.height;
}

get scrollWidth(): number {

Check warning on line 891 in src/ScrollBox.ts

View workflow job for this annotation

GitHub Actions / build

Opening curly brace appears on the same line as controlling statement
return this.list.width;
}
}

0 comments on commit 9b51c72

Please sign in to comment.