AngularJS中的滚动事件 [英] Scroll event in AngularJS

查看:38
本文介绍了AngularJS中的滚动事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有滚动条的div。现在我希望得到一个事件,每次触发,用户滚动。

I have a div with a scrollbar in it. Now I want to get an event, that triggers every time, the user scrolls.

在AngularJS中是否可以,或者我必须使用jQuery吗?

Is that possible in AngularJS, or do I have to use jQuery for that?

编辑:
到目前为止,我想出了以下内容:

I came up with following so far:

// JS
.directive('scroll', function() {
    return function(scope, element, attrs){

        angular.element(element).bind("scroll", function(){
            console.log(1);
        });
    };
});

// HTML
<div class="wrapper" style="height: 1550px" scroll>
[...]
</div>

但这不起作用(我在Firebug-Console中看不到任何日志)。

But that does not work (I don't see any logs in my Firebug-Console).

推荐答案

Angular 1.6的解决方案:

Solution for Angular 1.6:

.directive("scroll", function () {
return {
  link: function(scope, element, attrs) {
      element.bind("wheel", function() {
         console.log('Scrolled below header.');
      });
  }
}

})

使用wheel而不是scroll。我需要几个小时才能找到。

Use "wheel" instead of "scroll". It takes me few hours to find.

这篇关于AngularJS中的滚动事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆