1

On the click of a button i want the page to scroll a particular div bottom.

The 1st time i click, the page is going to the very top and the initial url http://localhost:8000 becomes http://localhost:8000/#/bottom(why is it not going to the div i mentioned).

The 2nd time i click the button, the url becomes http://localhost:8000/#/bottom#bottom and it goes to the div bottom(which is what i want).

How do i deal with this ?

code snippet

$location.hash('bottom');
$anchorScroll();

Thanks in advance

Do ask for more explanation if required . . .

dreamer
  • 901
  • 2
  • 15
  • 38

2 Answers2

0

I don't know if you still need help, but have you checked this question?

Anyway, I also use one button to do a anchor scroll:

<button ng-click="app.gotoAnchor('destination')">GO!</button>
(...)
<div id="destination" style="height:1px;"></div>

And I just used a combination of AngularJS documentation examples and the SO question I mentioned before, to make this function:

function gotoAnchor(anchor){
      if ($location.hash() !== newHash) {
        // set the $location.hash to `newHash` and
        // $anchorScroll will automatically scroll to it
        $timeout(function() {
          $location.hash(anchor);
        });
      } else {
        // call $anchorScroll() explicitly,
        // since $location.hash hasn't changed
        $anchorScroll();
      }
    }

Being the $timeout call the one that made this work better.

Hope this helps.

Community
  • 1
  • 1
Ciso
  • 23
  • 4
-3
<a href="#bottom">BOTTOM</a>
<div style="height:700px"> this is boby </div>
<a href="https://www.facebook.com/vietlink365" id="bottom">JOIN NOW!</a>