# anchorScroll offset

**URL:** <https://forum.ionicframework.com/t/anchorscroll-offset/20210>\
**Category:** ionic-v1\
**Created:** [April 3, 2015, 4:10am UTC](https://forum.ionicframework.com/t/anchorscroll-offset/20210 "2015-04-03T04:10:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ztoork](https://avatars.discourse-cdn.com/v4/letter/z/f19dbf/32.png) [@ztoork](https://forum.ionicframework.com/u/ztoork)\
**Post date:** [April 3, 2015, 4:10am UTC](https://forum.ionicframework.com/t/anchorscroll-offset/20210/1 "2015-04-03T04:10:49Z")

</div>

Can someone please tell me how to set the yOffset when calling $ionicScrollDelegate.anchorScroll(true)? I have banged my head against the wall on this for nearly 6 hours!!! I saw that there were a few threads about this a while ago and a Github response said that it was fixed using the “ScrollBy()” element, but there is no documentation on this. I have a really “hacky” hack working - but I’d love to have a real solution. Anybody??

---

<div class="post-metadata">

**Author:** ![kirrg](https://avatars.discourse-cdn.com/v4/letter/k/8797f3/32.png) [@kirrg](https://forum.ionicframework.com/u/kirrg)\
**Post date:** [April 3, 2015, 11:18am UTC](https://forum.ionicframework.com/t/anchorscroll-offset/20210/2 "2015-04-03T11:18:40Z")

</div>

there is documentation on it

see [http://ionicframework.com/docs/api/service/$ionicScrollDelegate/](http://ionicframework.com/docs/api/service/%24ionicScrollDelegate/)

```
 scrollBy(left, top, [shouldAnimate]) (The y-offset to scroll by.)
```

---

<div class="post-metadata">

**Author:** ![ztoork](https://avatars.discourse-cdn.com/v4/letter/z/f19dbf/32.png) [@ztoork](https://forum.ionicframework.com/u/ztoork)\
**Post date:** [April 3, 2015, 4:36pm UTC](https://forum.ionicframework.com/t/anchorscroll-offset/20210/3 "2015-04-03T16:36:35Z")

</div>

Thanks for the quick reply! So I got scrollBy() to work, but not in conjunction with anchorScroll(). I need it to target specific elements with and offset… not just move it a bit. $ionicScrollDelegate.anchorScroll().scrollBy(0, 80, true); \<\<\< that’s what I’m looking for, but it doesn’t work. Am I missing something?

---

<div class="post-metadata">

**Author:** ![kirrg](https://avatars.discourse-cdn.com/v4/letter/k/8797f3/32.png) [@kirrg](https://forum.ionicframework.com/u/kirrg)\
**Post date:** [April 3, 2015, 4:42pm UTC](https://forum.ionicframework.com/t/anchorscroll-offset/20210/4 "2015-04-03T16:42:34Z")

</div>

anchorScroll is defined by using a hash (or if no hash, scroll to top)  
an anchor is either top, bottom, middle or whatever they define.  
i think you are maybe miss-understanding the feature?

what you can do is: describe exactly what should happen. maybe we can help you then.

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [April 3, 2015, 5:08pm UTC](https://forum.ionicframework.com/t/anchorscroll-offset/20210/5 "2015-04-03T17:08:23Z")

</div>

Hey there, so anchor scrolling is handled a bit differently in angular.

So while traditional javascript/jquery you could just do this.

```auto

<div id="link"></div>

<a href="#link">got to #link</a>

```

Anular treats the # a bit differently.  
Since internally they use that in part of their page linking, it will expect you to be going to a view who’s urls is `link`, not anchor scroll.

So to work around this, they have you pass in a hash to the to window location

[https://docs.angularjs.org/api/ng/service/$anchorScroll](https://docs.angularjs.org/api/ng/service/%24anchorScroll)

An example of this with angular and ionic can be seen here

> **[FmyaB](https://codepen.io/mhartington/pen/FmyaB)**
>
> ...

---

<div class="post-metadata">

**Author:** ![ztoork](https://avatars.discourse-cdn.com/v4/letter/z/f19dbf/32.png) [@ztoork](https://forum.ionicframework.com/u/ztoork)\
**Post date:** [April 5, 2015, 1:37pm UTC](https://forum.ionicframework.com/t/anchorscroll-offset/20210/6 "2015-04-05T13:37:43Z")

</div>

So I found a resolution to this (kind of). What I ended up doing is targeting the anchor to the previous FAQ and that gave me the result I needed although it is not a solution to the yOffset not working. Here’s the code - if it would help:

$scope.faqClick = function(index){  
if(index != 0) {  
$location.hash(“faq”+(index-1));  
$ionicScrollDelegate.anchorScroll(true);  
$timeout(function() { $location.hash(""); }, 1000);  
}  
}

---

<div class="post-metadata">

**Author:** ![hchau619](https://avatars.discourse-cdn.com/v4/letter/h/91b2a8/32.png) [@hchau619](https://forum.ionicframework.com/u/hchau619)\
**Post date:** [November 13, 2015, 9:17pm UTC](https://forum.ionicframework.com/t/anchorscroll-offset/20210/7 "2015-11-13T21:17:01Z")

</div>

In case it still matter. This works for me.

$scope.scrollTo = function(id) {  
if($location.hash() !== id){  
$location.hash(id);  
$ionicScrollDelegate.anchorScroll(true);  
$ionicScrollDelegate.scrollBy(0, [yoffset], true);  
}  
};
