离子/角度指令绑定到滚动
Ionic / angular directive bind to scroll
我有这个滚动的div:
<div class="list">
<div class="item" ng-repeat="post in posts">
<img src="post.img" is-visible/>
</div>
</div>
这在一项指令中:
angular.element(window).on('DOMContentLoaded load resize scroll', function () {
console.log("window change");
});
目标是检测滚动。问题是只有load
和resize
在触发控制台注释。上下滚动列表不会触发它。为什么不呢?
您正在滚动到具有ng-repeat
指令的特定div
,&您已经在window
上应用了滚动。直到滚动到窗口,它才会着火。
理想情况下,您应该将滚动事件设置为将包装在ng-repeat
元素上的特定事件。因此,它可以作为posts
集合的滚动条容器。
标记
<div is-visible id="post-list" class="list" style="overflow-y:scroll;width: 400px;height: 120px;border: 1px solid gray;">
<div id="post-{{$index}}" class="item card" ng-repeat="post in posts">
Message: {{post.message}}
</div>
</div>
指令
.directive('isVisible', function(){
return {
restrict: 'A',
link: function(scope, element, attrs) {
element.on('scroll', function(){
console.log('Scroll has been detected.');
})
}
}
})
Plunkr
HTML嵌入在<ion-content></ion-content>
块中,这就是滚动。。。所以这就是我需要绑定的:
HTML
<ion-content id="my-content">
<div is-visible id="post-list" class="list" style="overflow-y:scroll;width: 400px;height: 120px;border: 1px solid gray;">
<div id="post-{{$index}}" class="item card" ng-repeat="post in posts">
Message: {{post.message}}
</div>
</div>
</ion-content>
指令
.directive('isVisible', function(){
return {
restrict: 'A',
link: function(scope, element, attrs) {
var parent = angular.element(document.querySelector('#my-content'));
parent.on('scroll', function(){
console.log('Scroll has been detected.');
})
}
}
})
相关文章:
- 在D3.js中,有没有任何方法可以将x和y方向上的滚动事件绑定到平移svg
- jquery:将动画绑定到滚动条位置的更好方法
- 从父元素取消绑定滚动事件并绑定到子元素
- 视差 - 偏移元素,绑定到滚动
- 绑定'滚动'不会'我在IE 11中不工作
- 离子/角度指令绑定到滚动
- 将DIV元素绑定到溢出滚动条
- 动画(绑定到 scrollTop)仅在我停止滚动时完成
- 触摸事件的挖空事件绑定导致滚动问题
- 滚动事件未绑定在指令内 - 角度.js
- 将垂直滚动位置绑定到计数器
- 绑定此鼠标滚轮事件处理程序将禁用垂直滚动
- angular:绑定到滚动事件不起作用
- slimScroll销毁不't取消绑定滚动事件
- 如何绑定和解除绑定无限ajax滚动,以便其他jQuery正常工作
- 绑定滚动事件-如何解除绑定
- jQuery激活(绑定)滚动后解除绑定
- 无法及时绑定滚动事件
- 如何同时使用Math.max()和Math.min()来绑定滚动块?
- jQuery -绑定滚动停止事件