2015-01-23 1 views
0

에 앵커 리디렉션 :방법 페이지 상단 앵커가 AngularJS와

<a href="#top">Logo goes here</a> 

페이지 하단에서이 문의 양식이 있습니다. 문의 양식을 작성한 후 앵커에게 페이지 상단으로 이동하고 싶습니다.

$location.path("#top") 

도움이되지 않았습니다.

어떻게 하시겠습니까?

답변

1

각을 이루십시오. $anchorScroll 매뉴얼 페이지의 예제는 맨 위가 아니라 맨 아래로 스크롤하는 것을 제외하고는 원하는 것입니다. ...

+2

예 또는 다른 사람이 아니 더주고 좋은 것 그 링크 유일한 대답 – Satpal

0

$ anchorScroll이 방법입니다. 다음은 그 사용의 예 :

var myApp = angular.module('myApp', []); 

myApp.controller('myController', function ($scope, $location, $anchorScroll) { 
    $scope.gotoBottom = function(myTarget) { // this is the function to call with ng-click 
     $location.hash(myTarget); // set the target 
     $anchorScroll(); // scroll to the target that has been set 
    }; 
}]); 

는 그런 다음 같은 HTML있을 것은 다음

<div ng-controller="myController"> 
    <a ng-click="gotoBottom('goHere')">Scroll to my target location</a> 
    <p>Some random stuff</p> 
    <p>Some random stuff</p> 
    <p>Some random stuff</p> 
    <a id="goHere">This is where you scroll to</a> 
</div>