1

I have recently inserted a "jump to anchor" within a page on my Angular page. When clicking on the href it scrolls down correctly but it returns to the start position directly after. I can't figure out what is the issue.

HTML:

<a ng-click="scrollTo('my-location')" ui-sref="partial.page"></a>
<a id="my-location"></a>

JavaScript:

$scope.scrollTo = function (hash) {
   $location.hash(hash);
}

I tried preventing the default, like this:

HTML:

JavaScript:

$scope.scrollTo = function (hash, $event) {
   $event.preventDefault();
   $location.hash(hash);
}

And that solves the jumping problem, but it's not opening the partial page within the page anymore.

How do I make it scroll to, not jump back, and open the partial page?

Henri
  • 11
  • 3
  • *(continuing)* ...because the question should have mentioned the partial in the first place -- but hey, you're new here. :-) Removing my answer puts the question back on the list of unanswered questions. Good luck!! I hope someone has a good answer for you! – T.J. Crowder Dec 10 '19 at 11:54
  • 1
    Thank you TJ fore your effort. Hopefully this will be responded soon. – Henri Dec 10 '19 at 13:48

0 Answers0