如何知道div中滚动条的位置?

ani*_*CSE 1 html javascript scrollbar angularjs

我想得到滚动条的实际位置(scrollY),如下所示. http://plnkr.co/edit/45gKhAIt0DrozS7f0Bz2?p=preview
我需要为我的div而不是整个窗口获取这种类型的scrollY结果.我怎么能在angularjs中做到这一点?

angular.element($window).bind('scroll',function(){
    console.log(' --- You scrolled - do $digest() ---')
    $scope.scrollY = $window.scrollY;
    $scope.$digest();
})
Run Code Online (Sandbox Code Playgroud)

The*_*One 8

这里不是棱角分明的,只是标准的JavaScript: .scrollTop

yourDiv.scrollTop
Run Code Online (Sandbox Code Playgroud)

示例:http://jsfiddle.net/TheSharpieOne/Tf7bq/2/(该值记录在控制台中.)

UPDATE

更改了侦听器以侦听div上的滚动.Angular没有很好的方法来监听滚动(就像它对某些其他事件一样),因此使用标准的JavaScript事件监听器.您可以将其包装在指令中以使其更具角度.

新例子:http://jsfiddle.net/TheSharpieOne/Tf7bq/4/

yourDiv.addEventListener('scroll',function(){

    console.log(this.scrollTop);

});
Run Code Online (Sandbox Code Playgroud)