gpt4 book ai didi

javascript - AngularJS 中的滚动事件

转载 作者:数据小太阳 更新时间:2023-10-29 04:26:14 25 4
gpt4 key购买 nike

我有一个带有滚动条的 div。现在我想获得一个事件,每次用户滚动时都会触发。

这在 AngularJS 中可行吗,还是我必须为此使用 jQuery?

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

// 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 控制台中没有看到任何日志)。

最佳答案

Angular 1.6 的解决方案:

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

})

用“wheel”代替“scroll”。我花了几个小时才找到。

关于javascript - AngularJS 中的滚动事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26588300/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com