angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

$anchorScroll Offset

Open leeola opened this issue 13 years ago • 53 comments

Just a quick feature request.

If your app has a fixed position header, $anchorScroll will "incorrectly" position the scroll for the users view. Nothing is broke here, but allowing for an $anchorScrollProvider offset number would be nice.

Basically, right after elm.scrollIntoView() it would execute roughly.. if (offset > 0) $window.scroll($window.scrollX, $window.scrollY - offset);. This would allow $anchorScrollProvider & $anchorScroll to play nicely with fixed position headers.

leeola avatar Feb 25 '13 23:02 leeola

Funny enough, i noticed that even the official docs suffer from this same problem.

http://docs.angularjs.org/api/AUTO.$provide#factory

Notice how when you visit that url, you cannot see the title for that documentation? It's because it is hidden behind the page header, haha.

leeola avatar Feb 28 '13 00:02 leeola

Volunteer

davidchang avatar Mar 06 '13 07:03 davidchang

Actually, the underlying scroll functionality comes from https://developer.mozilla.org/en-US/docs/DOM/element.scrollIntoView which doesn't allow for an offset. Doing the $window.scroll after calling elm.scrollIntoView() may be obviously hacky.

davidchang avatar Mar 06 '13 19:03 davidchang

+1 for a solution to this problem

andymcfee avatar Apr 18 '13 09:04 andymcfee

+1 here as well. Probably not uncommon to want a 10-20 pixel offset from the element being scrolled to.

kapilkale avatar Jul 04 '13 00:07 kapilkale

Actually, the underlying scroll functionality comes from https://developer.mozilla.org/en-US/docs/DOM/element.scrollIntoView which doesn't allow for an offset. Doing the $window.scroll after calling elm.scrollIntoView() may be obviously hacky.

Yea, that's why i haven't asked for my code to be pulled in. It's hacky, but i'm not aware of any other way. Anchors on my site would be broken without it heh.

leeola avatar Jul 04 '13 00:07 leeola

+1 here too.

rickhuizinga avatar Jul 17 '13 21:07 rickhuizinga

I wrote the following in my controller. Really awful hack put could not figure any other way. Am new to Angular; but thought i would share.

$scope.goToInternalHash = function(id, offset) { $location.hash(id); $anchorScroll(); setTimeout(function(){ window.scrollTo(window.pageXOffset, window.pageYOffset - offset); },300);

yellowrangler avatar Jul 18 '13 17:07 yellowrangler

Adding invisible anchor tags with negative relative offset seems like a nice workaround for this issue, e.g. http://stackoverflow.com/a/13184714/295416

trask avatar Sep 01 '13 17:09 trask

Might as well be using angular-ui and bootstrap Scrollspy or wrapping some other plugin in a service.

ghost avatar Sep 20 '13 21:09 ghost

I have the same problem.

pavelnikolov avatar Oct 05 '13 21:10 pavelnikolov

+1 for a solution to this

There are any number of little hacks that can be implemented, but it would be nice if there was something built in.

rjelte avatar Nov 05 '13 19:11 rjelte

+1

mikeobrien avatar Nov 12 '13 03:11 mikeobrien

+1

mrzepinski avatar Nov 14 '13 10:11 mrzepinski

+1

paul-lemon avatar Dec 08 '13 21:12 paul-lemon

+1

ada-lovecraft avatar Dec 13 '13 02:12 ada-lovecraft

+1

maltenuhn avatar Dec 20 '13 13:12 maltenuhn

+1

deepak-nulu avatar Dec 26 '13 00:12 deepak-nulu

+1

voxmatt avatar Jan 19 '14 00:01 voxmatt

+1

akarl avatar Jan 23 '14 15:01 akarl