diff --git a/src/directives/scroll_spy.coffee b/src/directives/scroll_spy.coffee index 73c0406..174e0b9 100644 --- a/src/directives/scroll_spy.coffee +++ b/src/directives/scroll_spy.coffee @@ -26,7 +26,11 @@ angular.module("Mac").directive("macScrollSpy", [ scrollHeight = this.scrollHeight or element[0].scrollHeight maxScroll = scrollHeight - spyElement.height() - return true if scrollTop >= maxScroll or not scrollSpy.registered.length + return true unless scrollSpy.registered.length + + # Select the last anchor when scrollTop is over maxScroll + if scrollTop >= maxScroll and scrollSpy.active.id isnt scrollSpy.last().id + return scrollSpy.setActive scrollSpy.last() for i in [0..scrollSpy.registered.length - 1] anchors = scrollSpy.registered diff --git a/src/services/scroll_spy.coffee b/src/services/scroll_spy.coffee index 7fe4e1b..c5c31ce 100644 --- a/src/services/scroll_spy.coffee +++ b/src/services/scroll_spy.coffee @@ -67,6 +67,9 @@ angular.module("Mac").service("scrollSpy", [ @registered[i..i] = [] break + last: -> + @registered[@registered.length - 1] + setActive: (anchor) -> @active = anchor listener(anchor) for listener in @listeners