Remembering Scroll Position

Ionic 10 beta

$stateProvider.state(‘profile’, function(){
url: ‘profile/:profileId’,
views: {}
});

Bumping this for no reply in 2 days

Hey there, sorry I’ve been crazy busy!

So have you tried beta 11 or the nightly builds?

Also, check out the docs for ionicScrolllDeleagate.

http://ionicframework.com/docs/api/service/$ionicScrollDelegate/

In that modal view, you can set an action to either forget the scroll position or scroll back to the top

<ion-item ng-click="backUp()" ng-href="...">
  person info here
</ion-item>
$scope.backUp = function(){
   $ionicScrollDelegate.scrollTop(false);
   //Or this could work too.
   // $ionicScrollDelegate.forgetScrollPosition()
};

Upgraded to beta 11 last night same issue.

This is how I want to tackle my profile page issue. Any feedback would be greatly appreciated.

  • On state change start grab the users scroll position, and the current hash.
  • Add to a global object (service) with the key being the hash and the value being the scroll position.
var positions = {
'#/profile/1': 282, '#/profile/2': 582
};

Then after an ajax call is made for a page check this global attribute to see if the user has been to this page before. If they have take them to the desired scroll position like so

if(positions['#/profile/1']) {
$ionicScrollDelegate.scrollTo(0, positions['#/profile/1'], false);
}

If they have not been to that specific hash keep them at the top like so 

else {
$ionicScrollDelegate.scrollTo(0, 0, false);
}

This way I am not taking them half way down the screen when they visit a profile that they have not been to before like they currently are right now.

  1. Will this effectively overwrite the scroll remembering code you guys already have in place
  2. Is this necessary or will there be a tighter scroll remembering feature that is based off hash and not view in a future build

You could do that, or you could do this much simpler solution.

The only thing I see that has to do with scrolling in this code pen is

$ionicScrollDelegate.$getByHandle(‘main’).scrollTop(true);

Please elaborate on how this is a better solution to saving scroll positions based on the current page the user is on.

Well, I look at it as being a simpler solution really.
With out looking at your project, it’s kind of hard to put together the best solution, or even to figure out why you are having this issue to being with. I can always take a look at help you out if you want