Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You should bind scroll event to document as document is the element that is scrolling. Then you can detect the <code>scrollTop</code> of document and compare with the offset of the repeating items.</p> <p>JSFiddle Demo: <a href="http://jsfiddle.net/daiweilu/nzBS5/2/" rel="nofollow">http://jsfiddle.net/daiweilu/nzBS5/2/</a></p> <p>I only use jQuery and Angular 1.2.6. Basically I tested the top border of ng-repeat item against window top border. If an item starts to leave window, the function on ng-repeat item is executed once. If the item came back and leave again, the function will be triggered again.</p> <p>HTML</p> <pre><code>&lt;div ng-controller="MyCtrl" scrollable-container&gt; &lt;div ng-repeat="article in articles" class="block" scrollable-item="atNewArticle(article)"&gt; &lt;h1&gt;{{article.title}}&lt;/h1&gt; &lt;p&gt;{{article.body}}&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>JS var app = angular.module('myApp', []);</p> <pre><code>app.directive('scrollableContainer', function($window, $document) { return { link: function(scope, element, attrs) { angular.element($document).on('scroll', function() { var children = element.children(); var $leftChild; for (var i = 0; i &lt; children.length; i++) { var $child = $(children[i]); var childTop = $child.offset().top; var docScrollTop = $document.scrollTop(); var scope = $child.scope(); if (childTop - docScrollTop &lt; 0) { if (!scope._left) { scope._left = true; $leftChild = $child; } } else { delete scope._left; } } if ($leftChild) { $leftChild.scope().$eval( $leftChild.attr('scrollable-item') ); } }); } }; }); function MyCtrl($scope) { $scope.articles = [ {title:'article1',body:'body of article1'}, {title:'article2',body:'body of article2'}, {title:'article3',body:'body of article3'} ]; $scope.atNewArticle = function (article) { //i only execute when transitioning back and forth between articles console.log(article); }; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload