在angularjs指令中,如何检测用户是否已停止滚动。
.directive('scrollable', ['$document', '$window', function ($document, $window, ) {
return {
link: function (scope, element, attrs) {
$document.bind('scroll', function() {
// detect if scroll has stop and execute a function
});
}
};
}]);
答案 0 :(得分:1)
您需要在一段时间后手动检测它,例如250ms: -
$document.bind('scroll', function() {
clearTimeout( $.data( this, "scrollCheck" ) );
$.data( this, "scrollCheck", setTimeout(function() {
//Here you can call a function after scroll stopped
}, 250) );
});
<强>更新强>: -
工作plunker