2017-04-25 5 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をリストしていませんでした。

答えて

0

私はディレクティブ

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(); 
     }); 
    }; 
}); 
を管理するための最良の方法だと思います。この

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

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

をお試しください

関連する問題