angularjs - $anchorScroll not functioning properly -
on click of button want page scroll particular div bottom
.
the 1st time click, page going top , initial url http://localhost:8000
becomes http://localhost:8000/#/bottom
(why not going div
mentioned).
the 2nd time click button, url becomes http://localhost:8000/#/bottom#bottom
, goes div bottom
(which want).
how deal ?
code snippet
$location.hash('bottom'); $anchorscroll();
thanks in advance
do ask more explanation if required . . .
i don't know if still need help, have checked this question?
anyway, use 1 button anchor scroll:
<button ng-click="app.gotoanchor('destination')">go!</button> (...) <div id="destination" style="height:1px;"></div>
and used combination of angularjs documentation examples , question mentioned before, make function:
function gotoanchor(anchor){ if ($location.hash() !== newhash) { // set $location.hash `newhash` , // $anchorscroll automatically scroll $timeout(function() { $location.hash(anchor); }); } else { // call $anchorscroll() explicitly, // since $location.hash hasn't changed $anchorscroll(); } }
being $timeout
call 1 made work better.
hope helps.
Comments
Post a Comment