Last active
June 12, 2018 08:11
-
-
Save sp90/9d1ee0956c1a56567e429b446d6b0b4b to your computer and use it in GitHub Desktop.
Simplest infinite scroll module (194 bytes GZIPPED)
This file contains hidden or 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() { | |
'use strict'; | |
var modules = []; | |
angular | |
.module('directive.whenScrolled', modules) | |
.directive('whenScrolled', whenScrolled); | |
function whenScrolled() { | |
return { | |
restrict: 'A', | |
link: function(scope, elem, attrs) { | |
// we get a list of elements of size 1 and need the first element | |
var raw = elem[0]; | |
// we load more elements when scrolled past a limit | |
elem.bind('scroll', function() { | |
if (raw.scrollTop + raw.offsetHeight + 5 >= raw.scrollHeight) { | |
scope.loading = true; | |
// we can give any function which loads more elements into the list | |
scope.$apply(attrs.whenScrolled); | |
} | |
}); | |
} | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment