2017-04-25 67 views
0
<ul> 
    <li></li> 
    <li></li> 
</ul> 

当我滚动到页面的底部时,我希望页面加载<li>info</li>使用onscroll事件更新列表

$window.onscroll = function($event){ 
        if($window.pageYOffset > [the parent element height]){ 
         //TODO 
        } 
        }; 

那么我怎样才能得到父元素的高度使用角?我试图访问https://docs.angularjs.org/api/ng/service/ $ window来查找相关的api,但是这个页面没有列出$ window的attr,顺便说一下,我怎样才能获得$ window中所有attrs的角度。

回答

0

试试这个

$document.on('scroll', function() { 
    // do your things 
    console.log($window.scrollY); 

    // or pass this to the scope 
    $scope.$apply(function() { 
     $scope.pixelsScrolled = $window.scrollY; 
    }) 
}); 

我认为管理指令

app = angular.module('myApp', []); 
app.directive("scroll", function ($window) { 
    return function(scope, element, attrs) { 

     angular.element($window).bind("scroll", function() { 
      if (this.pageYOffset >= 100) { 
       scope.boolChangeClass = true; 
       console.log('Scrolled below header.'); 
      } else { 
       scope.boolChangeClass = false; 
       console.log('Header is in view.'); 
      } 
      scope.$apply(); 
     }); 
    }; 
}); 
最好的方法