AngularJS指令 - 检测滚动是否已停止并执行功能

时间:2015-03-29 12:37:31

标签: angularjs angularjs-directive

在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        
        });
    }
};
}]);

1 个答案:

答案 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