0

There is an application that listens to scrolling the screen by the user. So that's why if the scrolling is done with the mouse wheel, the data comes an order of magnitude slower than if you scroll the page with a space.

Server code is not laid out, there is no point. Below is the application code.

@HostListener('window:scroll', ['$event']) checkScroll() {
    if (!this.getdata) {
        const componentPosition = this.el.nativeElement.offsetTop;
        const componentHeight =  this.el.nativeElement.getBoundingClientRect().height;
        const scrollPosition = window.pageYOffset;
        const windowheight = window.outerHeight;
        const needposition = componentPosition + componentHeight - windowheight - 500;

        if (scrollPosition >= needposition) {
            this.getdata = true;
            this.getMoreNew();
        }
    }

}

getMoreNew() {
    if (!this.nomoredata) {
        const city = this.city;
        const find = this.find;
        const last = this.persones[this.persones.length - 1]['orderbyname'];
        this.httpClient.post<Array<any>>('/assets/api/index.php', {action: 'person', type: this.type, last, limit: this.limit, city, find })
            .subscribe(
                data => {
                    if (data.length === 0) {
                        this.nomoredata = true;
                        this.getdata = false;
                    } else {
                        this.persones = this.persones.concat(data);
                        this.getdata = false;
                    }
                }
            );
    } else {
        this.getdata = false;
    }

}

See screenshot from devtools:

Eric
  • 6,563
  • 5
  • 42
  • 66

1 Answers1

0

I am not entirely sure what the question is, but I think it's that your scroll is too slow and you want to have a way to help offload the computation for the event? You could try using a debounce to ignore the scrolling until the user is done.

rhavelka
  • 2,283
  • 3
  • 22
  • 36
  • The problem is this. If i refresh the page in the browser and start scrolling with the mouse, the data upload and add is slower if scrolling by space upload and add quickly. Also I noticed that if I go to the page with the upload module from another route, then everything works quickly and with a mouse and a space. I do not understand why this happens and I would like to understand it. Try it self if you want https://lprotect.ru/advocate – askidmobile Jun 23 '18 at 19:49