Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

anchorScroll() forces Android address bar to show #1718

Closed
viceversus opened this issue Dec 18, 2012 · 1 comment
Closed

anchorScroll() forces Android address bar to show #1718

viceversus opened this issue Dec 18, 2012 · 1 comment

Comments

@viceversus
Copy link

The code below found in $anchorScrollProvider forces the Android address bar to show. The scroll method is called every time angular changes views, which causes this issue. While iOS and other browsers allow 0 in the scrollTo method, Android allows only positive integers for the desired behavior (http://mobile.tutsplus.com/tutorials/mobile-web-apps/remove-address-bar/).

function scroll() {
  var hash = $location.hash(), elm;

  // empty hash, scroll to the top of the page
  if (!hash) $window.scrollTo(0, 0);

  // element with given id
  else if ((elm = document.getElementById(hash))) elm.scrollIntoView();

  // first anchor with given name :-D
  else if ((elm = getFirstAnchor(document.getElementsByName(hash)))) elm.scrollIntoView();

  // no element and hash == 'top', scroll to the top of the page
  else if (hash === 'top') $window.scrollTo(0, 0);
}

Our fix is to wrap window's scrollTo method and check if the device is an Android. If it is an android and the x, y arguments are 0, 0, we manually set the value to 0, 1.

window.aliasedScrollTo = window.scrollTo

window.scrollTo = (x, y, delay) ->
  if Device.android() && x == 0 && y == 0
    window.aliasedScrollTo(x, 1, delay)
  else
    window.aliasedScrollTo(x, y, delay)

Is there a better solution for this problem?

@btford btford closed this as completed Aug 24, 2013
@btford
Copy link
Contributor

btford commented Aug 24, 2013

As part of our effort to clean out old issues, this issue is being automatically closed since it has been inactivite for over two months.

Please try the newest versions of Angular (1.0.8 and 1.2.0-rc.1), and if the issue persists, comment below so we can discuss it.

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants