anchorScroll() Issue

I want to auto-scroll to a certain point on a page marked by an id. The problem is that once it scrolls to that point, I can’t scroll back up to the top of the page manually. The anchor becomes the new top of the page.

Does anybody know how to escape this problem?

Here is my code.

  var handle = $ionicScrollDelegate.$getByHandle('content');

I am also getting the following warning on my console. I already have it wrapped in a timeout as well.

Delegate for handle “content” could not find a corresponding element with delegate-handle=“content”! anchorScroll() was not called!
Possible cause: If you are calling anchorScroll() immediately, and your element with delegate-handle=“content” is a child of your controller, then your element may not be compiled yet. Put a $timeout around your call to anchorScroll() and try again.

Do I need to set the handle to an ID at the top of the page afterwards? It may scroll to the very top of the page then?

var old = $location.hash();
var handle = $ionicScrollDelegate.$getByHandle(‘content’);

1 Like

I tried that and the page just scrolled back up to the top unfortunately!

I fixed it in the end by using a different method.

function scrollToAdvert(eleID){

var advertId = document.getElementById(eleID);
var top = getElementOffset(advertId).top;
top = top - 200;
$ionicScrollDelegate.scrollBy(0, top, true)


function getElementOffset(element)
var de = document.documentElement;
var box = element.getBoundingClientRect();
var top = + window.pageYOffset - de.clientTop;
var left = box.left + window.pageXOffset - de.clientLeft;
return { top: top, left: left };