Home > Web Front-end > JS Tutorial > body text

AngularJS module learning Anchor Scroll_AngularJS

WBOY
Release: 2016-05-16 15:19:10
Original
1376 people have browsed it

As the saying goes: a good memory is not as good as a bad pen. This article will take notes on the angularjs module learning. First, we will start learning from the anchor scroll. Please see below for the specific content:

•$anchorScroll() is used to jump to the definition ID;
•The hash() method of the $location object will replace the current url as the hash key;
•$anchorScroll() reads and jumps to the ID.

Simple example below, here is the output:

Source code index.html--11 lines, marked jump 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>
Copy after login

app.js

var demoApp = angular.module("app",[])
.controller("MockController",
function ($scope, $location, $anchorScroll) {
$scope.numbers = {
"自然数":["","","","","","","","","","","","","","","","","","","",""],
"质数":["","","","","","", "", "", "", ""]
};
$scope.jumper = function(key){
$location.hash(key);
$anchorScroll();
}
});
Copy after login

The above is the relevant content of Anchor Scroll for AngularJS module learning compiled by the editor. I hope you like it.

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!