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

ScrolledUp Event issue #373

Closed poddarkhushbu07 closed 2 months ago

poddarkhushbu07 commented 3 years ago

Expected Behaviour

scrolledUp should be triggered when scroll reaches the top of container.

Actual Behavior

I am using ngx-infinite-scroll for my chat module. I want an event when scrollbar is at top of the container. For this, scrolledUp output event is present, but in my case it is not getting triggered on currentScrollPosition:0. It is triggered after scrollbar is scrolled down a bit after reaching top position. i.e. currentScrollPosition:2 / currentScrollPosition:3.

infiniteScrollUpDistance:9.9
infiniteScrollThrottle: 1000
chatScrollDistance: 0

Version used: ^10.0.0 Browser Name and version: Chrome

BarkhatovN commented 3 years ago

I have same problem

BarkhatovN commented 3 years ago

There are 2 points We should look for

ngx-infinite-scroll uses throttleTime with default configuration (leading value emits) so if you scroll to top in throttled interval, it will emit only first value, that could not satisfy infiniteScrollUpDistance check

For example, infiniteScrollUpDistance=2(scrollTop should be less then 20% of scrollHeight to emit event), scrollTop= 1000 scrollHeight=2000, throttle interval=500ms. If you scroll to top in that interval, only scrollTop=999 might be handled, so needed event wouldn't be emitted

Also It has problem with browser behaviour. When scrollTop=0 and scrollHeight changes it doesn't change scrollTop, so we need scroll programmatically before add new elements (to scroll top 1 as Example) to let browser change scrollTop (navigate us to last shown element) when we add some elements in container

orizens commented 2 years ago

please try latest v13

mi-wit commented 2 years ago

I have the same issue (^13.0.2). It is also present in Chromium browser, but less often

My solution: Make the scrollable list always 'scrolled down a bit':

image