How can I measure if request animation frame helped to my scroll event?

Discussão em 'Angular' iniciado por Andrej code, Março 4, 2025.

  1. Andrej code

    Andrej code Guest

    I have the following code

    ngAfterViewInit() {

    this.viewportElementRef.nativeElement.addEventListener('scroll', this.onScroll);

    }

    private onScroll = (event: Event & { target: HTMLElement }): void => {
    console.log('scroll event");


    attached on some div, i wonder if i use request animation frame

    private scrollTimeout: any;
    private onScroll = (event: Event & { target: HTMLElement }): void => {
    if (this.scrollTimeout) {
    cancelAnimationFrame(this.scrollTimeout);
    }
    this.scrollTimeout = requestAnimationFrame(() => {
    this.handleScroll(event.target);
    });
    };

    private handleScroll(target: HTMLElement): void {
    console.log('scroll event");
    }


    how can i check if now my scroller event is better ? Because i am npt able to see any difference when i scroll throguh big data or to see some difference dependent on the console logs in the scroll method

    I tried using console logs to see soem differences but now able to do that

    Continue reading...

Compartilhe esta Página