orizens / ngx-infinite-scroll

Infinite Scroll Directive for Angular
https://www.npmjs.com/package/ngx-infinite-scroll
MIT License
1.23k stars 223 forks source link

Scroll down function is getting called multiple times on scrolling down #200

Closed khanna-912 closed 6 years ago

khanna-912 commented 6 years ago

Scroll down function gets called multiple time on scrolling down. It should be called just once on scrolling down each time.

miro-orpheus commented 6 years ago

I have same problem. If I scroll down scrolled is triggered multiple times (scroll is not to bottom of the page). My code is this. `<div class="timeline" infiniteScroll [infiniteScrollDistance]="1" [infiniteScrollThrottle]="300" (scrolled)="getTimelineData()"

<app-timeline-day-box *ngFor="let event of timeline;" [event ]="event ">

`

FilipeQ commented 6 years ago

this happens on scroll down and up

miro-orpheus commented 6 years ago

@FilipeQ on scroll down.

miro-orpheus commented 6 years ago

I fixed this problem with adding "infiniteScrollDisabled". Now my code is: <div class="timeline" infiniteScroll [infiniteScrollDistance]="1" [infiniteScrollThrottle]="1500" [infiniteScrollDisabled]="blockInfiniteScroll" (scrolled)="getTimelineData()" > <app-timeline-day-box *ngFor="let event of timeline;" [event ]="event "></app-timeline-day-box> </div>

byrenx commented 6 years ago

I've encountered also with the same issue, it continue to call scroll function even if I just scroll down once. This happens when I insert DFP ad banner from google as an item in my list view. But, when I remove the ads in the template it works fine. I don't know if it has something to do with the iframe that google ads added to the template?

ebakke commented 6 years ago

Here's what I'm seeing.

Any short/slow scrolling towards the end of the window will trigger multiple scrolled events. Even if the user doesn't start/stop scrolling (by lifting the finger from a trackpad, for example) but just continues scrolling at a slow rate. scrolled will be fired once every infiniteScrollThrottle milliseconds until the first call to get more results has completed and the new items have been rendered on the page.

This can also happen if a user keeps hitting/bouncing against the bottom of the window while a page of results are fetched.

After a cursory glance, it seems that the event should only be triggered once per IPositionStats.totalToScroll. If that hasn't changed, the event should not be triggered again. That may not handle all cases.

orizens commented 6 years ago

@ebakke you're right. an enhancement of triggering once until totalToScroll has change is the way.

orizens commented 6 years ago

fixed by 269b5f6dd84125698620ffce8f0f8b4b1a1bafe5

kamal0912 commented 5 years ago

fixed by 269b5f6

Hi @orizens , Can you please specify what exactly do I need to write in my code to fix this issue? You have marked this issue as closed, but I am unable to see any solution for it. If I scroll fast, scroll event fires multiple times and this is causing huge problem for me as every scroll down call makes a request to server. Event should get called once the user is done with scrolling. Please help.

ghost commented 4 years ago

I am facing the same issue. It can not seem to be working. Can you give a hint what can be done to get it running propertly (1load per scroll)?

aakash-p-27 commented 3 years ago

Hey, I am also facing the same issue. Can you please suggest to me what can be done to running properly?

TGihan commented 3 years ago

i am also having the same issue. Its duplicating items in my list and send multiple requests to the server. How to prevent multiple scroll event trigger?

angularui06 commented 3 years ago

I got the same issue and fixed using infiniteScrollDisabled Property (Angular 6)

Html

<div
      [ngClass]="{'search-results': transactionRows?.length > 0}"
      infiniteScroll
      [infiniteScrollDistance]="2"
      [infiniteScrollThrottle]="50"
      [scrollWindow]="false"
      **[infiniteScrollDisabled]="busyGettingData"**
      (scrolled)="onScroll()"
    ></div>

TS

busyGettingData = false;

  onScroll() {
    if (this.busyGettingData) {
      return
    }
    this.busyGettingData = true
  this.getAPIData();
  }

getAPIData() {
   // API Success Block
    this.busyGettingData = false

 // API Error Block
this.busyGettingData = false
}
sunny7899 commented 3 years ago

@angularui06 Thanks working fine in my case.

Rakshithkakathkar commented 3 years ago

Wow, this is so cool Thank you @angularui06! 😃

lzatloukal commented 6 months ago

@angularui06 It`s working. Thank you for the solution.