AngularJS模組學習之Anchor Scroll_AngularJS

來源:互聯網
上載者:User

俗話說的好:好記性不如一個爛筆頭,本文對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 的相關內容,希望大家喜歡。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.