转自: http://www.cnblogs.com/mrxia/p/3868126.html
具体的文章我就不转载了. 粘贴下公司项目逇实现吧
<span style="font-size:14px;">/*@author Tushar Borole
* @description user has to jsut mention the percent, on completion of that percentage scroll; expression will be fired
* for example <div id="fixed" when-scrolled="loadMore()" percent="70">*/
var scroll = angular.module('angular-scroll-complete', []);
scroll.run(function() {
document.ontouchmove = function(e) {
e.preventDefault();
};
});
scroll.directive('whenScrolled', function () {
return function ($scope, elm, attr) {
var raw = elm[0];
var scrollCompleted = true;
$scope.$on('scrollCompleted', function () {
scrollCompleted = true;
});
$scope.scrollCompleted = function() {
scrollCompleted = true;
};
elm.bind('scroll', function() {
var scroll = elm.data("iscroll");
var remainingHeight = raw.offsetHeight - raw.scrollHeight;
var scrollTop = raw.scrollTop;
if (scroll != null)
scrollTop = scroll.y;
var percent = Math.abs((scrollTop / remainingHeight) * 100);
if (percent > attr.percent) {
if (scrollCompleted) {
scrollCompleted = false;
$scope.$apply(attr.whenScrolled);
}
}
});
};
});
scroll.directive('ngScroll', function($interval) {
return function($scope, elm, attr) {
if (elm.children().length > 1)
{
elm.children().wrapAll("<div></div>");
}
var scroll = new IScroll(elm[0], {
bounce: false,
scrollbars: false,
click: true,
probeType: 1
});
elm.data("iscroll", scroll);
scroll.on("scroll", function() {
elm.scroll();
});
$interval(function() {
try
{
scroll.refresh();
} catch(err)
{ }
}, 500);
};
});
</span>