当前位置: 移动技术网 > IT编程>脚本编程>AngularJs > AngularJS模块学习之Anchor Scroll

AngularJS模块学习之Anchor Scroll

2019年05月29日  | 移动技术网IT编程  | 我要评论

俗话说的好:好记性不如一个烂笔头,本文对angularjs模块学习笔记,首先我们从anchor scroll开始学习,具体内容请看下文:

•$anchorscroll()用于跳转至定义id;
•$location对象的hash()方法会替换当前url作为hash键;
•$anchorscroll()读取并跳转至id处。

下面简单的例子,这里是输出结果:

源码 --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 的相关内容,希望大家喜欢。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网