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



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

您需要在一段时间后手动检测它,例如250ms:-

 $document.bind('scroll', function() {
clearTimeout( $.data( this, "scrollCheck" ) );
                $.data( this, "scrollCheck", setTimeout(function() {
                    //Here you can call a function after scroll stopped
                }, 250) );      
        });

更新:-

工作柱塞

最新更新