Last active
April 6, 2017 19:57
-
-
Save rootux/cbf99fb0931d24c563147cd0c3cac87a to your computer and use it in GitHub Desktop.
Angular 1.5 - Calls a method when user scrolls to bottom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function OnScrollToBottom() { | |
'ngInject'; | |
let spacing = 40; | |
return { | |
restrict: 'A', | |
link: function (scope, element, attrs) { | |
const fn = attrs.onScrollToBottom, | |
clientHeight = element[0].clientHeight; | |
element.on('scroll', function (e) { | |
const el = e.target; | |
if ((el.scrollHeight - el.scrollTop) <= clientHeight + spacing) { | |
scope.$apply(fn); | |
} | |
}); | |
} | |
}; | |
} | |
export default OnScrollToBottom; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can call it like so:
<div class='viewport' on-scroll-to-bottom="$ctrl.loadMorePosts()">