17

I use the $anchorScroll-service in AngularJS. It works fine. But I have a fixed navigation bar at the top and the scrolling location goes always x-pixels to far.

Now in the $anchorScroll documentation there is a property called yOffset. According to the documentation it should fix my problem.

I don't know how to use this yOffset-property however, because this specific part has no example.

How can I use the yOffset-property of the $anchorScroll-service?

DanEEStar
  • 6,140
  • 6
  • 37
  • 52

1 Answers1

31

There is an example that illustrates how to use yOffset at the bottom of the $anchorScroll documentation.

// offset position by 100px down from the top
$anchorScroll.yOffset = 100;

This is the example plunker

Robert Koritnik
  • 103,639
  • 52
  • 277
  • 404
merlin
  • 784
  • 1
  • 15
  • 22
  • 6
    Never scrolled down enough... How adequate for this question :) – DanEEStar Oct 24 '14 at 08:15
  • 1
    This can be used right above the $anchorScroll too for individual sets. – Organiccat May 07 '15 at 15:49
  • 10
    Anybody ever followed the docs and had this not work? I'm in the boat, trying to determine what the "obvious" component is that I am missing. Doesn't seem like there's much to mess up, I just set `$anchorScroll.yOffset = 100;` on a module run then have a `goTo()` function in a controller. Changing the `$anchorScroll.yOffset` value fails to have any effect. – kuanb Aug 24 '15 at 23:50
  • 3
    Wait, you mean that you set it using a global mutable property which can screw up every other call to $anchorscroll ? In what world is this a good idea ? – Valentin Waeselynck Sep 24 '15 at 17:23
  • I'm using material-design-lite - Material Design Components in CSS, JS and HTML and am attempting to offset an anchorScroll for elements in mdl-layout__content. The offset doesn't work; looks like it's incompatible. – Daniel F Sep 28 '15 at 17:23
  • Setting the yOffset does not work . I did $anchorScroll.yOffset = -105; in the app run , but it does not seam to work for some reason . – 32teeths Feb 19 '16 at 06:21
  • If you're having trouble getting yOffset working and your URL hashes and anchor IDs are the same, check first that it's not the native browser anchor scroll that you're experiencing - that will not take into account any `yOffset`. – poshest Jan 23 '18 at 11:41