ajoslin / angular-scrolly

Fake transform-scrolling with angular-friendly utilities
http://ajoslin.github.io/angular-scrolly
65 stars 7 forks source link

Make scroller recalculate height on digest, throttled/lazily #16

Closed ajoslin closed 11 years ago

ajoslin commented 11 years ago

In an app I'm making, I have a button which hides a bunch of items on a list.

If I'm scrolled halfway down a list of twenty items, then suddenly hide all but two of them with a button, the scroller will still be halfway down and no content will be shown.

To fix this, we could have scrolly calculateHeight on digest - but lazily, only if it hasn't calculated it in last 200ms or so.

This won't cover everything, but it will help and stop it from being a big performance hit.

something like this:

var justCalculated = false;
$rootScope.$watch(function() {
  if (!justCalculated) {
    justCalculated = true;
    calculateHeight();
    checkBoundaries();
    setTimeout(function() {
      justCalculated = false;
    }, 200);
  }
});
ajoslin commented 11 years ago

People can call myScroller.recalculateHeight() if they want to. Closing.