俗話說的好:好記性不如一個爛筆頭,本文對angularjs模組學習筆記,首先我們從anchor scroll開始學習,具體內容請看下文:
•$anchorScroll()用於跳轉至定義ID;
•$location物件的hash()方法會取代目前url作為hash鍵;
•$anchorScroll()讀取並跳轉至ID處。
下面簡單的例子,這裡是輸出結果:
原始碼 index.html--11行,標示了的跳轉ID:
<!DOCTYPE html> <html ng-app="app"> <head> <script src="angular.min.js"></script> <script src="app.js"></script> <meta charset="utf-"> </head> <body ng-controller="MockController"> <button ng-repeat="(key, value) in numbers" ng-click="jumper(key)"> {{key}} </button> <div ng-repeat="(key, value) in numbers" id="{{key}}"> <h>{{key}}</h> <ol> <ul ng-repeat="item in value"> {{item}} </ul> </ol> </div> </body> </html>
app.js
var demoApp = angular.module("app",[]) .controller("MockController", function ($scope, $location, $anchorScroll) { $scope.numbers = { "自然数":["","","","","","","","","","","","","","","","","","","",""], "质数":["","","","","","", "", "", "", ""] }; $scope.jumper = function(key){ $location.hash(key); $anchorScroll(); } });
以上所述是小編給大家整理的AngularJS模組學習之Anchor Scroll 的相關內容,希望大家喜歡。