首頁 > web前端 > js教程 > 主體

AngularJS模組學習之Anchor Scroll_AngularJS

WBOY
發布: 2016-05-16 15:19:10
原創
1394 人瀏覽過

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

來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板