patrickmarabeas / ng-ScrollSpy.js

An AngularJS module for navigation highlighting
http://patrickmarabeas.github.io/ng-ScrollSpy.js
MIT License
26 stars 9 forks source link

Add support for custom scroll element (other than window) #14

Open kmturley opened 8 years ago

kmturley commented 8 years ago

Can you add support for passing through a custom element which has overflow-y: scroll?

It could be passed through like this:

element: document.getElementById('main')

ng-ScrollSpy.js line could have:

.value('config', {
  'offset': 200,
  'delay': 100,
  'element': window
})

And a new refresh position function:

'refreshPositions': function() {
  this.position.documentHeight = Math.max(config.element.scrollHeight, config.element.offsetHeight, config.element.clientHeight);
  if (config.element.pageYOffset) {
      this.position.windowTop = config.element.pageYOffset;
  } else if (config.element.scrollTop) {
      this.position.windowTop = config.element.scrollTop;
  } else {
      this.position.windowTop = (document.documentElement || document.body.parentNode || document.body).scrollTop;
  }
  this.position.windowBottom = this.position.windowTop + window.innerHeight
}

I've posted an example script here: https://gist.github.com/kmturley/043cd096a0e8239bea18

jondubois commented 8 years ago

:+1: