2017-04-25 69 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(); 
     }); 
    }; 
}); 
最好的方法