【发布时间】:2016-09-15 06:32:09
【问题描述】:
我想记录窗口从文档顶部的偏移量,但 jquery 滚动不起作用。 vanilla javascript 滚动事件监听器会在 Angular 中工作吗?
app.directive('owlCarouselItem', function($touch, $timeout, $rootScope, $window){
return {
restrict: 'C',
transclude: false,
link: function(scope, element) {
// this is the part of my directive the on scroll event is not firing
$('html, body').on('scroll', function() {
if($(this).scrollTop() == 0){
console.log($(this).scrollTop());
canSwipeDown = true;
}else{
console.log($(this).scrollTop());
canSwipeDown = false;
}
});
【问题讨论】:
-
你能告诉我们你做了什么以及你在控制器/指令等的什么地方实现了这个吗? jQuery 应该可以很好地检测滚动,尤其是在 AngularJS(非 Angular 2)中
-
你为什么使用
restrict: C?您是否认真使用owlCarouselItem作为评论?
标签: javascript angularjs