Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding initial page feature #8

Closed
wants to merge 8 commits into from
13 changes: 13 additions & 0 deletions src/angular-vs-repeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,19 @@
$scope.offsetAfter = 0;
$scope.excess = 2;

$scope.$watch($attrs.vsInitialElement, function(elementIndex){
$scope.goTo(elementIndex);
});

$scope.goTo = function(index){
$scope.$$postDigest(function(){
var scrollPosition = (sizesPropertyExists) ?
($scope.sizesCumulative[index] + $scope.offsetBefore):
(index * $scope.elementSize + $scope.offsetBefore);
$scrollParent[0].scrollTop = scrollPosition;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more thing. This assumes that we are using vertically stacked element. Whereas vs-repeat also supports scrolling horizontally. Instead of referencing scrollTop use the scrollPos variable that i declare in the linking function.

});
};

Object.keys(attributesDictionary).forEach(function(key){
if($attrs[key]){
$attrs.$observe(key, function(value){
Expand Down