这是一个自定义的指令,试图使用退房,但不起作用。我可以删除退出,但在我的网络中,将有额外的2-4调用时,用户滚动到页面底部。如何解决这个问题?
angular.module('app')
.directive('checkBottom', function($document, $window) {
return function(scope, elm, attr) {
$document.bind('scroll', function() {
if( ($window.innerHeight + $window.scrollY) > $document.innerHeight() - 50) {
_.debounce(applyFunc, 100 ); // this don't work?
function applyFunc(){
scope.$apply(attr.checkBottom);
}
}
});
};
});发布于 2016-12-12 05:17:31
_.debounce()为以后的使用创建一个函数;调用它不是为了调用您的函数。基于文档,您可以这样使用它:
var applyFunc = applyFunc(){
scope.$apply(attr.checkBottom);
}
var debouncedApplyFunc = _.debounce(applyFunc, 100 );
angular.module('app')
.directive('checkBottom', function($document, $window) {
return function(scope, elm, attr) {
$document.bind('scroll', function() {
if( ($window.innerHeight + $window.scrollY) > $document.innerHeight() - 50) {
debouncedApplyFunc();
}
});
};
});https://stackoverflow.com/questions/41094256
复制相似问题