stackfull / angular-virtual-scroll

Source for the sf.virtualScroll module for AngularJS
MIT License
262 stars 42 forks source link

Make scrolling stick to bottom of list? #23

Closed hirohope closed 10 years ago

hirohope commented 10 years ago

I've been reading the code to understand how it was made, but I can't figure out why is necessary to modify the scrollTop if the scroll it's already there.

if( sticky ){
  viewport[0].scrollTop = viewport[0].clientHeight + viewport[0].scrollHeight;
}

This is in 61b0cdc

stackfull commented 10 years ago

When a new element is added to the collection, the viewport gets longer but browsers will keep the scroll position where it is (measured from the top). So to get auto-scroll, you have to adjust scrollTop to keep it pinned. The sticky flag is set whenever the user scrolls to the bottom so it's not always on.

hirohope commented 10 years ago

But when I add elements, wouldn't I want to keep the scroll position in the former last element and not go to the new last one? Why did you want this behaviour?

stackfull commented 10 years ago

Auto-scrolling is useful for log views. Anywhere you want to see the latest realtime data. It never occurred to me that people might want to turn it off! I guess an "autoscroll" attribute would make sense.

hirohope commented 10 years ago

Oh you're right. In the project I'm working the new data goes on top of the list and not bottom. Thanks for your answers.